include_level::include_level( cstring file_name, cstring path_separators, include_level* parent_ )
    : m_parent( parent_ )
{
    if( file_name.is_empty() )
        return;

    assign_op( m_curr_location.first, file_name, 0 );
    m_curr_location.second = 0;

    m_stream.open( m_curr_location.first.c_str() );

    if( !m_stream.is_open() && !!m_parent.get() ) {
        cstring            parent_path = m_parent->m_curr_location.first;
        cstring::iterator  it          = unit_test::find_last_of( parent_path.begin(), parent_path.end(),
                                         path_separators.begin(),
                                         path_separators.end() );

        if( it != parent_path.end() ) {
            assign_op( m_curr_location.first, cstring( parent_path.begin(), it+1 ), 0 );
            m_curr_location.first.append( file_name.begin(), file_name.end() );
            m_stream.clear();
            m_stream.open( m_curr_location.first.c_str() );
        }
    }

    BOOST_RT_PARAM_VALIDATE_LOGIC( m_stream.is_open(), BOOST_RT_PARAM_LITERAL( "couldn't open file " ) << file_name );
}
void
config_file_iterator::Impl::substitute_macros( cstring& where )
{
    m_post_subst_line.clear();
    cstring::size_type pos;

    while( (pos = where.find( m_macro_ref_begin )) != cstring::npos ) {
        m_post_subst_line.append( where.begin(), pos );

        where.trim_left( where.begin() + pos + m_macro_ref_begin.size() );

        pos = where.find( m_macro_ref_end );

        BOOST_RT_PARAM_VALIDATE_LOGIC( pos != cstring::npos, BOOST_RT_PARAM_LITERAL( "incomplete macro reference" ) );

        cstring value = *get_macro_value( where.substr( 0, pos ), false );
        m_post_subst_line.append( value.begin(), value.size() );

        where.trim_left( where.begin() + pos + m_macro_ref_end.size() );
    }

    if( !m_post_subst_line.empty() ) {
        m_post_subst_line.append( where.begin(), where.size() );
        where = m_post_subst_line;
    }
}
Beispiel #3
0
inline void
putenv_impl( cstring name, cstring value )
{
    using namespace std;
    // !! this may actually fail. What should we do?
    setenv( name.begin(), value.begin(), 1 );
}
inline bool
interpret_argument_value( cstring source, hexerboost::optional<std::list<T> >& res, int )
{
    BOOST_RT_PARAM_TRACE( "In interpret_argument_value<std::list<T>>" );

    res = std::list<T>();

    while( !source.is_empty() ) {
        // !! should we use token_iterator
        cstring::iterator single_value_end = std::find( source.begin(), source.end(), BOOST_RT_PARAM_LITERAL( ',' ) );

        hexerboost::optional<T> value;
        interpret_argument_value( cstring( source.begin(), single_value_end ), value, 0 );

        res->push_back( *value );

        source.trim_left( single_value_end + 1 );
    }

    return true;
}
Beispiel #5
0
 basic_param( cstring name, bool is_optional, bool is_repeatable, Modifiers const& m )
 : p_name( name.begin(), name.end() )
 , p_description( nfp::opt_get( m, description, std::string() ) )
 , p_help( nfp::opt_get( m, runtime::help, std::string() ) )
 , p_env_var( nfp::opt_get( m, env_var, std::string() ) )
 , p_value_hint( nfp::opt_get( m, value_hint, std::string() ) )
 , p_optional( is_optional )
 , p_repeatable( is_repeatable )
 , p_has_optional_value( m.has( optional_value ) )
 , p_has_default_value( m.has( default_value ) || is_repeatable )
 , p_callback( nfp::opt_get( m, callback, callback_type() ) )
 {
     add_cla_id( help_prefix, name, ":" );
 }
static bool
is_valid_identifier( cstring const& source )
{
    if( source.is_empty() )
        return false;

    cstring::const_iterator it = source.begin();

    if( !std::isalpha( *it ) )
        return false;

    while( ++it < source.end() ) {
        if( !std::isalnum( *it ) && *it != BOOST_RT_PARAM_LITERAL( '_' ) && *it != BOOST_RT_PARAM_LITERAL( '-' ) )
            return false;
    }

    return true;
}
bool
config_file_iterator::Impl::get_next_line( cstring& line )
{
    bool broken_line = false;

    line.clear();

    while( !m_curr_level->m_stream.eof() || !!m_curr_level->m_parent.get() ) {
        // 10. Switch to upper include level if current one is finished
        // 20.  Read/append next file line
        // 30.  Increment line number
        // 40.  Remove comments
        // 50.  Remove trailing and leading spaces
        // 60.  Skip empty string
        // 70.  Concatenate broken lines if needed. Put the result into line
        // 80.  If line is not completed, try to finish it by reading the next line
        // 90.  Process command line
        // 100. Substitute macros references with their definitions
        // 110. Next line found.

        if( m_curr_level->m_stream.eof() ) {                                                // 10 //
            m_curr_level = m_curr_level->m_parent;
            continue;
        }

        std::ifstream&  input   = m_curr_level->m_stream;
        char_type* buffer_insert_pos = broken_line ? m_buffer.get() + line.size() : m_buffer.get();

        input.getline( buffer_insert_pos, (std::streamsize)(m_buffer_size - line.size()),   // 20 //
                       m_line_delimeter );

        cstring next_line( buffer_insert_pos,
                           input.gcount() > 0
                           ? buffer_insert_pos + (input.eof() ? input.gcount() : (input.gcount()-1))
                           : buffer_insert_pos );


        m_curr_level->m_curr_location.second++;                                             // 30 //

        cstring::size_type comment_pos = next_line.find( m_sl_comment_delimeter );
        if( comment_pos != cstring::npos )
            next_line.trim_right( next_line.begin()+comment_pos );                          // 40 //

        if( m_trim_trailing_spaces )                                                        // 50 //
            next_line.trim_right();
        if( m_trim_leading_spaces && !broken_line )
            next_line.trim_left();

        if( next_line.is_empty() ) {                                                        // 60 //
            if( m_skip_empty_lines )
                continue;
            else
                next_line.assign( buffer_insert_pos, buffer_insert_pos );
        }

        line = broken_line ? cstring( line.begin(), next_line.end() ) : next_line;          // 70 //

        broken_line = match_back( line, m_line_beak );
        if( broken_line ) {                                                                 // 80 //
            line.trim_right( 1 );
            continue;
        }

        if( match_front( line, m_command_delimeter ) ) {                                    // 90 //
            process_command_line( line );
            continue;
        }

        if( !is_active_line() )
            continue;

        substitute_macros( line );                                                          // 100 //

        return true;                                                                        // 110 //
    }

    BOOST_RT_PARAM_VALIDATE_LOGIC( !broken_line, BOOST_RT_PARAM_LITERAL( "broken line is not completed" ) );
    BOOST_RT_PARAM_VALIDATE_LOGIC( m_conditional_states.size() == 0,
                                   BOOST_RT_PARAM_LITERAL( "matching endif command is missing" ) );

    return false;
}
Beispiel #8
0
 // Constructor // !! could we eliminate shared_ptr
 explicit    logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {}
 std::string interpret( cstring, cstring source ) const
 {
     return std::string( source.begin(), source.size() );
 }