Ejemplo n.º 1
0
OGRErr OGR_SRSNode::exportToWkt( char ** ppszResult ) const

{
    char        **papszChildrenWkt = NULL;
    int         nLength = strlen(pszValue)+4;
    int         i;

/* -------------------------------------------------------------------- */
/*      Build a list of the WKT format for the children.                */
/* -------------------------------------------------------------------- */
    papszChildrenWkt = (char **) CPLCalloc(sizeof(char*),(nChildren+1));
    
    for( i = 0; i < nChildren; i++ )
    {
        papoChildNodes[i]->exportToWkt( papszChildrenWkt + i );
        nLength += strlen(papszChildrenWkt[i]) + 1;
    }

/* -------------------------------------------------------------------- */
/*      Allocate the result string.                                     */
/* -------------------------------------------------------------------- */
    *ppszResult = (char *) CPLMalloc(nLength);
    *ppszResult[0] = '\0';
    
/* -------------------------------------------------------------------- */
/*      Capture this nodes value.  We put it in double quotes if        */
/*      this is a leaf node, otherwise we assume it is a well formed    */
/*      node name.                                                      */
/* -------------------------------------------------------------------- */
    if( NeedsQuoting() )
    {
        strcat( *ppszResult, "\"" );
        strcat( *ppszResult, pszValue ); /* should we do quoting? */
        strcat( *ppszResult, "\"" );
    }
    else
        strcat( *ppszResult, pszValue );

/* -------------------------------------------------------------------- */
/*      Add the children strings with appropriate brackets and commas.  */
/* -------------------------------------------------------------------- */
    if( nChildren > 0 )
        strcat( *ppszResult, "[" );
    
    for( i = 0; i < nChildren; i++ )
    {
        strcat( *ppszResult, papszChildrenWkt[i] );
        if( i == nChildren-1 )
            strcat( *ppszResult, "]" );
        else
            strcat( *ppszResult, "," );
    }

    CSLDestroy( papszChildrenWkt );

    return OGRERR_NONE;
}
Ejemplo n.º 2
0
OGRErr OGR_SRSNode::exportToPrettyWkt( char ** ppszResult, int nDepth ) const

{
/* -------------------------------------------------------------------- */
/*      Build a list of the WKT format for the children.                */
/* -------------------------------------------------------------------- */
    char **papszChildrenWkt = static_cast<char **>(
        CPLCalloc(sizeof(char*),(nChildren+1)) );
    size_t nLength = strlen(pszValue)+4;

    for( int i = 0; i < nChildren; i++ )
    {
        papoChildNodes[i]->exportToPrettyWkt( papszChildrenWkt + i,
                                              nDepth + 1);
        nLength += strlen(papszChildrenWkt[i]) + 2 + nDepth*4;
    }

/* -------------------------------------------------------------------- */
/*      Allocate the result string.                                     */
/* -------------------------------------------------------------------- */
    *ppszResult = static_cast<char *>( CPLMalloc(nLength) );
    *ppszResult[0] = '\0';

/* -------------------------------------------------------------------- */
/*      Capture this nodes value.  We put it in double quotes if        */
/*      this is a leaf node, otherwise we assume it is a well formed    */
/*      node name.                                                      */
/* -------------------------------------------------------------------- */
    if( NeedsQuoting() )
    {
        strcat( *ppszResult, "\"" );
        strcat( *ppszResult, pszValue ); /* should we do quoting? */
        strcat( *ppszResult, "\"" );
    }
    else
        strcat( *ppszResult, pszValue );

/* -------------------------------------------------------------------- */
/*      Add the children strings with appropriate brackets and commas.  */
/* -------------------------------------------------------------------- */
    if( nChildren > 0 )
        strcat( *ppszResult, "[" );

    for( int i = 0; i < nChildren; i++ )
    {
        if( papoChildNodes[i]->GetChildCount() > 0 )
        {
            strcat( *ppszResult, "\n" );
            for( int j = 0; j < 4*nDepth; j++ )
                strcat( *ppszResult, " " );
        }
        strcat( *ppszResult, papszChildrenWkt[i] );
        if( i < nChildren-1 )
            strcat( *ppszResult, "," );
    }

    if( nChildren > 0 )
    {
        if( (*ppszResult)[strlen(*ppszResult)-1] == ',' )
            (*ppszResult)[strlen(*ppszResult)-1] = '\0';

        strcat( *ppszResult, "]" );
    }

    CSLDestroy( papszChildrenWkt );

    return OGRERR_NONE;
}
Ejemplo n.º 3
0
orl_return CreateNamedLabel( orl_symbol_handle sym_hnd )
{
    hash_data *         data_ptr;
    label_list          sec_label_list;
    label_entry         entry;
    orl_symbol_type     type;
    orl_symbol_type     primary_type;
    orl_sec_handle      sec;
    char *              SourceName;
    char *              LabName;
    unsigned_64         val64;

    type = ORLSymbolGetType( sym_hnd );
    primary_type = type & 0xFF;
    switch( primary_type ) {
// No harm in including these since elf generates relocs to these.
//      case ORL_SYM_TYPE_NONE:
//      case ORL_SYM_TYPE_FUNC_INFO:
//          return( ORL_OKAY );
        case ORL_SYM_TYPE_FILE:
            SourceName = ORLSymbolGetName( sym_hnd );
            if( (SourceName != NULL) && (SourceFileInObject == NULL) ) {
                SourceFileInObject = SourceName;
            }
            return( ORL_OKAY );
    }
    entry = MemAlloc( sizeof( label_entry_struct ) );
    if( !entry ) return( ORL_OUT_OF_MEMORY );
    val64 = ORLSymbolGetValue( sym_hnd );
    entry->offset = val64.u._32[I64LO32];
    // all symbols from the object file will have names
    entry->shnd = ORLSymbolGetSecHandle( sym_hnd );
    if( primary_type == ORL_SYM_TYPE_SECTION ) {
        entry->type = LTYP_SECTION;
    } else if( primary_type == ORL_SYM_TYPE_GROUP ) {
        entry->type = LTYP_GROUP;
    } else if( entry->shnd == 0 ) {
        entry->type = LTYP_EXTERNAL_NAMED;
    } else if( primary_type == ORL_SYM_TYPE_FUNC_INFO ){
        entry->type = LTYP_FUNC_INFO;
    } else {
        entry->type = LTYP_NAMED;
    }
    entry->binding = ORLSymbolGetBinding( sym_hnd );
    LabName = ORLSymbolGetName( sym_hnd );
    if( LabName == NULL ) {
        sec = ORLSymbolGetSecHandle( sym_hnd );
        if( sec ) {
            LabName = ORLSecGetName( sec );
        } else {
            MemFree( entry );
            return( ORL_OKAY );
        }
    }

    // Demangle the name, if necessary
    if( !((Options & NODEMANGLE_NAMES) || (DFormat & DFF_ASM)) ) {
        entry->label.name = MemAlloc( MAX_LINE_LEN + 3 );
        __demangle_l( LabName, 0, &(entry->label.name[2]), MAX_LINE_LEN );
    } else {
        entry->label.name = MemAlloc( strlen( LabName )+8 );
        strcpy( &(entry->label.name[2]), LabName );
    }

    entry->label.name[0]=0;
    entry->label.name[1]=0;
    LabName = &(entry->label.name[2]);
    if( NeedsQuoting( LabName ) ) {
        // entry->label.name[-1] will be 1 if we have added a quote,
        // 0 otherwise.  This is helpful when freeing the memory.
        entry->label.name[0] = 1;
        entry->label.name[1] = '`';
        entry->label.name += 1;
        LabName += strlen( LabName );
        LabName[0] = '`';
        LabName[1] = '\0';
    } else {
        entry->label.name += 2;
    }
    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) entry->shnd );
    if( data_ptr ) {
        sec_label_list = (label_list) *data_ptr;
        entry = addLabel( sec_label_list, entry, sym_hnd );
        if( Options & PRINT_PUBLICS && entry->shnd != 0 &&
                primary_type != ORL_SYM_TYPE_SECTION &&
                entry->binding != ORL_SYM_BINDING_LOCAL ) {
            Publics.number++;
        }
    } else {
        // error!!!! the label list should have been created
        MemFree( entry );
        return( ORL_ERROR );
    }
    return( ORL_OKAY );
}