Example #1
0
/*
    - list1 and list2 containts strings
    - if one of the strings in list2 is contained ( partial match, strstr() )
      in one of the strings in list1 the function returns true...
*/
bool nlt_namelist_intersect( const KNamelist *list1, const KNamelist *list2 )
{
    uint32_t count1;
    bool res = false;
    if ( list1 == NULL || list2 == NULL )
        return res;
    if ( KNamelistCount( list1, &count1 ) == 0 )
    {
        uint32_t idx1;
        for ( idx1 = 0; idx1 < count1 && res == false; ++idx1 )
        {
            const char *string1;
            if ( KNamelistGet( list1, idx1, &string1 ) == 0 )
            {
                uint32_t count2;
                if ( KNamelistCount( list2, &count2 ) == 0 )
                {
                    uint32_t idx2;
                    for ( idx2 = 0; idx2 < count2 && res == false; ++idx2 )
                    {
                        const char *string2;
                        if ( KNamelistGet( list2, idx2, &string2 ) == 0 )
                        {
                            if ( strstr( string1, string2 ) != NULL )
                                res = true;
                        }
                    }
                }
            }
        }
    }
    return res;
}
Example #2
0
/* read the mapping out of the region-types out of a string... */
rc_t rgn_extract_type_mappings( const KNamelist *rgn_names,
                                region_type_mapping *mapping, bool check_completenes )
{
    rc_t rc = 0;
    uint32_t count, idx;

    mapping->rgn_type_adapter = -1;
    mapping->rgn_type_insert  = -1;
    mapping->rgn_type_hq      = -1;
    mapping->rgn_type_ga      = -1;

    rc = KNamelistCount ( rgn_names, &count );
    for ( idx = 0; idx < count && rc == 0; ++idx )
    {
        const char *name;
        rc = KNamelistGet ( rgn_names, idx, &name );
        if ( rc == 0 )
            rgn_type_string( name, idx, mapping );
    }

    if ( rc == 0 && check_completenes )
    {
        if ( mapping->rgn_type_adapter == -1 ||
             mapping->rgn_type_insert == -1 ||
             mapping->rgn_type_hq == -1 )
            rc = RC( rcExe, rcNoTarg, rcLoading, rcName, rcIncomplete );
    }

    mapping->count_of_unknown_rgn_types = 0;
    return rc;
}
Example #3
0
static rc_t make_schema( const KNamelist * schema_list,
                  VDBManager *my_manager, VSchema ** schema )
{
    rc_t rc = VDBManagerMakeSchema ( my_manager, schema );
    if ( rc != 0 )
        LogErr( klogInt, rc, "VDBManagerMakeSchema() failed\n" );
    else
    {
        uint32_t count;
        rc = KNamelistCount ( schema_list, &count );
        if ( rc !=0 )
            LogErr( klogInt, rc, "KNamelistCount(schema-list) failed\n" );
        else
        {
            uint32_t i;
            for ( i = 0; i < count && rc == 0; ++i )
            {
                const char * name;
                rc = KNamelistGet ( schema_list, i, &name );
                if ( rc !=0 )
                    LogErr( klogInt, rc, "KNamelistGet(schema-list) failed\n" );
                else
                {
                    rc = VSchemaParseFile ( *schema, name );
                    if ( rc !=0 )
                        LogErr( klogInt, rc, "VSchemaParseFile() failed\n" );
                }
            }
        }
    }
    return rc;
}
Example #4
0
bool nlt_compare_namelists( const KNamelist *nl1, const KNamelist *nl2, uint32_t * found )
{
    bool res = false;
    if ( nl1 != NULL && nl2 != NULL )
    {
        uint32_t count_1;
        rc_t rc = KNamelistCount( nl1, &count_1 );
        if ( rc == 0 )
        {
            uint32_t count_2;
            rc = KNamelistCount( nl2, &count_2 );
            if ( rc == 0 && count_1 == count_2 )
            {
                uint32_t idx;
                uint32_t in_nl2 = 0;
                for ( idx = 0; idx < count_1 && rc == 0; ++idx )
                {
                    const char *s;
                    rc = KNamelistGet( nl1, idx, &s );
                    if ( rc == 0 && s != NULL && nlt_is_name_in_namelist( nl2, s ) )
                        in_nl2++;
                }
                res = ( rc == 0 && in_nl2 == count_1 );
                if ( found != NULL ) *found = in_nl2;
            }
        }
    }
    return res;
}
Example #5
0
rc_t nlt_remove_names_from_namelist( const KNamelist *source,
                                     const KNamelist **dest, const KNamelist *to_remove )
{
    rc_t rc = 0;
    uint32_t count;

    if ( source == NULL || dest == NULL || to_remove == NULL )
        return RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull );
    *dest = NULL;
    rc = KNamelistCount( source, &count );
    if ( rc == 0 && count > 0 )
    {
        VNamelist *cleaned;
        rc = VNamelistMake ( &cleaned, count );
        if ( rc == 0 )
        {
            uint32_t idx;
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *s;
                rc = KNamelistGet( source, idx, &s );
                if ( rc == 0 )
                {
                    if ( !nlt_is_name_in_namelist( to_remove, s ) )
                        rc = VNamelistAppend ( cleaned, s );
                }
                rc = VNamelistToConstNamelist ( cleaned, dest );
            }
        }
    }
    return rc;
}
Example #6
0
/* ----------------------------------------------------------------------------- */
static bool has_col( const VTable * tab, const char * colname )
{
    bool res = false;
    struct KNamelist * columns;
    rc_t rc = VTableListReadableColumns( tab, &columns );
    if ( rc == 0 )
    {
        uint32_t count;
        rc = KNamelistCount( columns, &count );
        if ( rc == 0 && count > 0 )
        {
            uint32_t idx;
            size_t colname_size = string_size( colname );
            for ( idx = 0; idx < count && rc == 0 && !res; ++idx )
            {
                const char * a_name;
                rc = KNamelistGet ( columns, idx, &a_name );
                if ( rc == 0 )
                {
                    int cmp;
                    size_t a_name_size = string_size( a_name );
                    uint32_t max_chars = ( uint32_t )colname_size;
                    if ( a_name_size > max_chars ) max_chars = ( uint32_t )a_name_size;
                    cmp = strcase_cmp ( colname, colname_size,
                                        a_name, a_name_size,
                                        max_chars );
                    res = ( cmp == 0 );
                }
            }
        }
        KNamelistRelease( columns );
    }
    return res;
}
Example #7
0
rc_t nlt_copy_namelist( const KNamelist *src, const KNamelist ** dst )
{
    VNamelist *v_names;
    rc_t rc = VNamelistMake ( &v_names, 5 );
    if ( rc == 0 )
    {
        uint32_t count;
        rc = KNamelistCount( src, &count );
        if ( rc == 0 )
        {
            uint32_t idx;
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *s;
                rc = KNamelistGet( src, idx, &s );
                if ( rc == 0 && s != NULL )
                    rc = VNamelistAppend ( v_names, s );
            }
        }
        if ( rc == 0 )
            rc = VNamelistToConstNamelist ( v_names, dst );
        VNamelistRelease( v_names );
    }
    return rc;
}
Example #8
0
bool namelist_contains( const KNamelist *names, const char * a_name )
{
    bool res = false;
    uint32_t count;
    rc_t rc = KNamelistCount( names, &count );
    if ( rc == 0 && count > 0 )
    {
        uint32_t idx;
        size_t a_name_len = string_size( a_name );
        for ( idx = 0; idx < count && rc == 0 && !res; ++idx )
        {
            const char * s;
            rc = KNamelistGet( names, idx, &s );
            if ( rc == 0 && s != NULL )
            {
                size_t s_len = string_size( s );
                size_t max_len = a_name_len > s_len ? a_name_len : s_len;
                int cmp = string_cmp( a_name, a_name_len, s, s_len, max_len );
                if ( cmp == 0 )
                    res = true;
            }
        }
    }
    return res;
}
Example #9
0
rc_t CopyDirectoryFiles( const KDirectory *source, KDirectory *dest ) {
  rc_t rc;
  KNamelist *list;
  const char *name;
  int i;
  uint32_t count;
  char resolved[1024];

  rc = KDirectoryList( source, &list, PathIsFile, NULL, ".");
  if (rc != 0)
    {
      /* This doesn't do what I thought. */
      KDirectoryResolvePath( source, false, resolved, 1024, ".");
      LOGERR ( klogInt, rc, resolved );
      return rc;
    }
  KNamelistCount(list, &count);
  for (i=0; i<count; i++) {
    KNamelistGet(list, i, &name);
    if (test) {
      fprintf(stderr, "Will copy %s\n", name);
    } else {
      CopyFileToFile( source, name, dest, (char *)name );
    }
  }
  return 0;
}
Example #10
0
bool vdcd_extract_from_phys_table( col_defs* defs, const VTable *my_table )
{
    bool col_defs_found = false;
    KNamelist *names;
    rc_t rc = VTableListPhysColumns( my_table, &names );
    DISP_RC( rc, "VTableListPhysColumns() failed" );
    if ( rc == 0 )
    {
        uint32_t n;
        uint32_t found = 0;
        rc = KNamelistCount( names, &n );
        DISP_RC( rc, "KNamelistCount() failed" );
        if ( rc == 0 )
        {
            uint32_t i;
            for ( i = 0; i < n && rc == 0; ++i )
            {
                const char *col_name;
                rc = KNamelistGet( names, i, &col_name );
                DISP_RC( rc, "KNamelistGet() failed" );
                if ( rc == 0 )
                {
                    vdcd_append_col( defs, col_name );
                    found++;
                }
            }
            col_defs_found = ( found > 0 );
        }
        rc = KNamelistRelease( names );
        DISP_RC( rc, "KNamelistRelease() failed" );
    }
    return col_defs_found;
}
Example #11
0
static rc_t copy_metadata_attribs ( const KMDataNode *snode, KMDataNode *dnode,
                                    const char *node_path, const bool show_meta )
{
    KNamelist *attrs;
    uint32_t i, count;
    rc_t rc = KMDataNodeListAttr ( snode, & attrs );
    DISP_RC( rc, "copy_metadata_child:KMDataNodeListAttr(src) failed" );
    if ( rc != 0 ) return rc;
    rc = KNamelistCount ( attrs, & count );
    for ( i = 0; rc == 0 && i < count; ++ i )
    {
        const char *attr;
        rc = KNamelistGet ( attrs, i, & attr );
        if ( rc == 0 )
        {
            char buffer [ 1024 ];
            size_t bytes;
            /* test for attr existence */
            rc = KMDataNodeReadAttr ( dnode, attr, buffer, sizeof buffer, & bytes );
            if ( rc != 0 )
            {
                rc = KMDataNodeReadAttr ( snode, attr, buffer, sizeof buffer, & bytes );
                if ( rc == 0 )
                {
                    if ( show_meta )
                        KOutMsg( "copy atr %s : %s\n", node_path, attr );
                    rc = KMDataNodeWriteAttr ( dnode, attr, buffer );
                }
            }
        }
        DISP_RC( rc, "copy_metadata_child:failed to copy attribute" );
    }
    KNamelistRelease ( attrs );
    return rc;
}
Example #12
0
static rc_t for_each_v_name( VNamelist *names, void *data, const name_fkt f )
{
    KNamelist *knames;
    uint32_t count, idx;
    rc_t rc = VNamelistToNamelist( names, (KNamelist **)&knames );
    display_rescode( rc, "VNamelistToNamelist failed", NULL );
    if ( rc == 0 )
    {
        rc = KNamelistCount( knames, &count );
        display_rescode( rc, "KNamelistCount failed", NULL );
        if ( rc == 0 )
        {
            for ( idx=0; idx<count; ++idx )
            {
                const char *my_path;
                rc = KNamelistGet( knames, idx, &my_path );
                display_rescode( rc, "KNamelistGet failed", NULL );
                if ( rc == 0 )
                    rc = f( data, my_path );
            }
        }
        KNamelistRelease( knames );
    }
    return rc;
}
Example #13
0
rc_t nlt_build_intersect( const KNamelist *nl1, const KNamelist *nl2, const KNamelist ** dst )
{
    VNamelist *v_names;
    rc_t rc = VNamelistMake ( &v_names, 5 );
	if ( rc == 0 )
	{
		/* loop through nl1: if a entry is found in nl2 -> add it to dst */
		uint32_t count;
		rc = KNamelistCount( nl1, &count );
		if ( rc == 0 )
		{
            uint32_t idx;
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *s;
                rc = KNamelistGet( nl1, idx, &s );
				if ( rc == 0 && s != NULL )
				{
					if ( nlt_is_name_in_namelist( nl2, s ) )
						rc = VNamelistAppend ( v_names, s );
				}
			}
		}
		if ( rc == 0 )
			rc = VNamelistToConstNamelist ( v_names, dst );
        VNamelistRelease( v_names );

	}
	return rc;	
}
Example #14
0
static rc_t ShowFiles(const KConfig* cfg, const Params* prm) {
    rc_t rc = 0;
    bool hasAny = false;
    uint32_t count = 0;
    KNamelist* names = NULL;
    rc = KConfigListIncluded(cfg, &names);
    if (rc == 0)
    {   rc = KNamelistCount(names, &count); }
    if (rc == 0) {
        uint32_t i = 0;

        if (prm->showMultiple) {
            OUTMSG(("<!-- Configuration files -->\n"));
            hasAny = true;
        }

        for (i = 0; i < count && rc == 0; ++i) {
            const char* name = NULL;
            if (rc == 0)
            {   rc = KNamelistGet(names, i, &name); }
            if (rc == 0) {
                OUTMSG(("%s\n", name));
                hasAny = true;
            }
        }
    }
    if (rc == 0 && hasAny)
    {   OUTMSG(("\n")); }

    RELEASE(KNamelist, names);

    return rc;
}
Example #15
0
static 
rc_t CC
_LoadKartScanPath ( struct XFSKartCollectionNode * Node )
{
    rc_t RCt;
    struct KDirectory * Directory;
    KNamelist * List;
    const char * Name;
    uint32_t Idx;
    uint32_t ListCount;

    RCt = 0;
    Directory = NULL;
    List = NULL;
    Name = NULL;
    Idx = 0;
    ListCount = 0;

    if ( Node == NULL ) {
        return XFS_RC ( rcNull );
    }

    if ( Node -> path == NULL ) {
        return XFS_RC ( rcInvalid );
    }

    RCt = KDirectoryNativeDir ( & Directory );
    if ( RCt == 0 ) {
        RCt = KDirectoryList (
                            Directory,
                            & List,
                            NULL,
                            NULL,
                            Node -> path
                            );
        if ( RCt == 0 ) {
            RCt = KNamelistCount ( List, & ListCount );
            if ( RCt == 0 ) {
                for ( Idx = 0; Idx < ListCount; Idx ++ ) {
                    RCt = KNamelistGet ( List, Idx, & Name );
                    if ( RCt == 0 ) {
                        RCt = _LoadKartItem ( Directory, Node, Name );
                    }
                    if ( RCt != 0 ) {
                        break;
                    }
                }
            }

            KNamelistRelease ( List );
        }

        KDirectoryRelease ( Directory );
    }

    return RCt;
}   /* _LoadKartScanPath () */
Example #16
0
static
rc_t ConfigRepoSet(DLList* repos, KConfig * kfg, const char* kfgPath, const char *dflt, uint8_t type)
{
    const KConfigNode *node;

    rc_t rc = KConfigOpenNodeRead ( kfg, & node, kfgPath );
    if ( rc == 0 )
    {
        KNamelist* children;
        rc = KConfigNodeListChild ( node, &children );
        if ( rc == 0 )
        {
            uint32_t count;
            rc = KNamelistCount ( children, &count );
            if ( rc == 0 )
            {
                uint32_t i;
                for (i = 0; i < count; ++i)
                {
                    const char* name;
                    rc = KNamelistGet ( children, i, &name );
                    if ( rc == 0 )
                    {
                        #define BufSize 4096
                        char buf[ BufSize ];
                        size_t bSize = string_size(kfgPath);
                        string_copy(buf, BufSize, kfgPath, bSize);
                        if (bSize + string_size(name) < sizeof(buf))
                        {
                            NCBIRepository* repo;
                            string_copy(buf + bSize, sizeof(buf) - bSize, name, string_size(name) + 1);
                            rc = ConfigRepo( kfg, dflt, buf, buf, type, &repo );
                            DLListPushTail( repos, (DLNode*) repo );
                        }
                        #undef BufSize
                    }
                    else
                    {
                        rc = RC ( rcSRA, rcMgr, rcConstructing, rcString, rcExcessive );
                    }
                    if ( rc != 0 )
                    {
                        break;
                    }
                }
            }
            KNamelistRelease ( children );
        }

        KConfigNodeRelease ( node );
    }
    if (GetRCState(rc) == rcNotFound)
    {
        return 0;
    }
    return rc;
}
Example #17
0
bool vdcd_extract_from_table( col_defs* defs, const VTable *my_table )
{
    bool col_defs_found = false;
    KNamelist *names;
    rc_t rc = VTableListCol( my_table, &names );
    DISP_RC( rc, "VTableListCol() failed" );
    if ( rc == 0 )
    {
        const VCursor *my_cursor;
        rc = VTableCreateCursorRead( my_table, &my_cursor );
        DISP_RC( rc, "VTableCreateCursorRead() failed" );
        if ( rc == 0 )
        {
            uint32_t n;
            uint32_t found = 0;
            rc = KNamelistCount( names, &n );
            DISP_RC( rc, "KNamelistCount() failed" );
            if ( rc == 0 )
            {
                uint32_t i;
                for ( i = 0; i < n && rc ==0; ++i )
                {
                    const char *col_name;
                    rc = KNamelistGet( names, i, &col_name );
                    DISP_RC( rc, "KNamelistGet() failed" );
                    if ( rc == 0 )
                    {
                        p_col_def def = vdcd_append_col( defs, col_name );
                        rc = VCursorAddColumn( my_cursor, &(def->idx), def->name );
                        DISP_RC( rc, "VCursorAddColumn() failed" );
                        if ( rc == 0 )
                        {
                            rc = VCursorDatatype( my_cursor, def->idx,
                                      &(def->type_decl), &(def->type_desc) );
                            DISP_RC( rc, "VCursorDatatype() failed" );
                            if ( rc == 0 )
                            {
                                found++;
                            }
                        }
                    }
                }
                col_defs_found = ( found > 0 );
            }
            rc = VCursorRelease( my_cursor );
            DISP_RC( rc, "VCursorRelease() failed" );
        }
        rc = KNamelistRelease( names );
        DISP_RC( rc, "KNamelistRelease() failed" );
    }
    return col_defs_found;
}
Example #18
0
static 
rc_t CC
_LoadKart ( struct XFSKartNode * Node )
{
    rc_t RCt;
    const struct XFSGapKart * Kart;
    struct KNamelist * List;
    uint32_t ListQ, ListI;
    const char * ListN;

    RCt = 0;
    Kart = NULL;
    List = NULL;
    ListQ = ListI = 0;
    ListN = NULL;

    XFS_CAN ( Node )

    RCt = _AddSignatureFile ( Node );
    if ( RCt == 0 ) {
        RCt = XFSGapKartDepotGet (
                            & Kart,
                            XFSNodeName ( & ( Node -> node . node ) )
                            );
        if ( RCt == 0 ) {

            RCt = XFSGapKartList ( Kart, & List, Node -> project_id );
            if ( RCt == 0 ) {
                RCt = KNamelistCount ( List, & ListQ );
                if ( RCt == 0 ) {
                    for ( ListI = 0; ListI < ListQ; ListI ++ ) {
                        RCt = KNamelistGet ( List, ListI, & ListN );
                        if ( RCt != 0 ) {
                            break;
                        }
                        RCt = _AddKartItem ( Node, Kart, ListN );
                        if ( RCt != 0 ) {
                            break;
                        }
                    }
                }

                KNamelistRelease ( List );
            }

            XFSGapKartRelease ( Kart );
        }
    }

    return RCt;
}   /* _LoadKart () */
Example #19
0
/*
 * calls VTableListReadableColumns to get a list of all column-names of the table
 * creates a temporary read-cursor to test and get the column-type
 * walks the KNamelist with the available column-names
 * tries to add every one of them to the temp. cursor
 * if the column can be added to the cursor, it is appended
 * to the column-definition list
*/
rc_t col_defs_extract_from_table( col_defs* defs, const VTable *table )
{
    KNamelist *names;
    rc_t rc;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( table == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = VTableListReadableColumns( table, &names );
    DISP_RC( rc, "col_defs_extract_from_table:VTableListReadableColumns() failed" );
    if ( rc == 0 )
    {
        const VCursor *cursor;
        rc = VTableCreateCursorRead( table, &cursor );
        DISP_RC( rc, "col_defs_extract_from_table:VTableCreateCursorRead() failed" );
        if ( rc == 0 )
        {
            uint32_t count;
            rc = KNamelistCount( names, &count );
            DISP_RC( rc, "col_defs_extract_from_table:KNamelistCount() failed" );
            if ( rc == 0 )
            {
                uint32_t idx;
                for ( idx = 0; idx < count && rc == 0; ++idx )
                {
                    const char *name;
                    rc = KNamelistGet( names, idx, &name );
                    DISP_RC( rc, "col_defs_extract_from_table:KNamelistGet() failed" );
                    if ( rc == 0 )
                    {
                        uint32_t temp_idx;
                        rc_t rc1 = VCursorAddColumn( cursor, &temp_idx, "%s", name );
                        DISP_RC( rc1, "col_defs_extract_from_table:VCursorAddColumn() failed" );
                        if ( rc1 == 0 )
                        {
                            rc = col_defs_append_col( defs, name );
                            DISP_RC( rc, "col_defs_extract_from_table:col_defs_append_col() failed" );
                        }
                    }
                }
            }
            rc = VCursorRelease( cursor );
            DISP_RC( rc, "col_defs_extract_from_table:VCursorRelease() failed" );
        }
        rc = KNamelistRelease( names );
        DISP_RC( rc, "col_defs_extract_from_table:KNamelistRelease() failed" );
    }
    return rc;
}
Example #20
0
    /* sort by cid */
    return VCtxIdCmp ( & a -> cid, & b -> cid );
}

#if 0 /* more for later */
static
rc_t create_cursor_all_readable_columns(const VTable *self,
                                        unsigned *ncol, uint32_t **idx,
                                        const VCursor **curs)
{
    KNamelist *list;
    rc_t rc = VTableListReadableColumns(self, &list);
    
    if (rc == 0) {
        rc = VTableCreateCursorReadInternal(self, curs);
        if (rc == 0) {
            uint32_t n;
            
            rc = KNamelistCount(list, ncol);
            if (rc == 0) {
                n = *ncol;
                *idx = malloc(n * sizeof(**idx));
                if (idx) {
                    unsigned i;
                    
                    for (i = 0; i != (unsigned)n; ++i) {
                        const char *name;
                        
                        rc = KNamelistGet(list, i, &name);
                        if (rc)
                            break;
                        rc = VCursorAddColumn(*curs, &(*idx)[i], name);
                        if (rc)
                            break;
                    }
                    if (rc)
                        free(*idx);
                }
                else
                    rc = RC(rcVDB, rcTable, rcValidating, rcMemory, rcExhausted);
            }
            if (rc)
                VCursorRelease(*curs);
        }
        KNamelistRelease(list);
    }
    if (rc) {
        *idx = NULL;
        *curs = NULL;
        *ncol = 0;
    }
    return rc;
}
Example #21
0
static
rc_t ReportBuild(const ReportFuncs *f, uint32_t indent, const VDBManager* mgr)
{
    rc_t rc = 0;
    KNamelist* list = NULL;
    reportOpen(indent, "Build", 1, "static", 's', "false");
    if (mgr) {
        rc_t rc2 = VDBManagerListExternalSchemaModules(mgr, &list);
        if (rc2 != 0) {
            reportError
                (indent + 1, rc2, "VDBManagerListExternalSchemaModules");
            if (rc == 0 && rc2 != 0)
            {   rc = rc2; }
        }
        else {
            uint32_t count = 0;
            rc2 = KNamelistCount(list, &count);
            if (rc2 != 0) {
                reportErrorStr(indent + 1, rc2, "KNamelistCount", "origin",
                               "VDBManagerListExternalSchemaModules");
                if (rc == 0 && rc2 != 0)
                {   rc = rc2; }
            }
            else {
                uint32_t i = 0;
                for (i = 0; i < count && rc2 == 0; ++i) {
                    const char* name = NULL;
                    rc2 = KNamelistGet(list, i, &name);
                    if (rc2 != 0) {
                        reportErrorStr(
                            indent + 1, rc2, "KNamelistGet", "origin",
                            "VDBManagerListExternalSchemaModules");
                        if (rc == 0 && rc2 != 0)
                        {   rc = rc2; }
                    }
                    else {
                        report(indent + 1, "Module", 1, "name", 's', name);
                    }
                }
            }
        }
        RELEASE(KNamelist, list);
        reportClose(indent, "Build");
    }
    return rc;
}
Example #22
0
static rc_t for_each_k_name( KNamelist *names, void *data, const name_fkt f )
{
    uint32_t count, idx;
    rc_t rc = KNamelistCount( names, &count );
    display_rescode( rc, "KNamelistCount failed", NULL );
    if ( rc == 0 )
    {
        for ( idx=0; idx<count; ++idx )
        {
            const char *my_path;
            rc = KNamelistGet( names, idx, &my_path );
            display_rescode( rc, "KNamelistGet failed", NULL );
            if ( rc == 0 )
                rc = f( data, my_path );
        }
    }
    return rc;
}
Example #23
0
static
void dump_tbl ( const KTable *tbl, const char *tblname, int argc, char *argv [] )
{
    if ( argc >= 4 )
    {
        int i;
        for ( i = 3; i < argc; ++ i )
        {
            dump_col_name ( tbl, argv [ 1 ], tblname, argv [ i ] );
        }
    }
    else
    {
        KNamelist *names;
        rc_t rc = KTableListCol ( tbl, & names );
        if ( rc != 0 )
            fprintf ( stderr, "failed to list columns for tbl '%s.%s'\n", argv [ 1 ], tblname );
        else
        {
            uint32_t count;
            rc = KNamelistCount ( names, & count );
            if ( rc != 0 )
                fprintf ( stderr, "failed to count columns for tbl '%s.%s'\n", argv [ 1 ], tblname );
            else
            {
                uint32_t i;
                for ( i = 0; i < count; ++ i )
                {
                    const char *name;
                    rc = KNamelistGet ( names, i, & name );
                    if ( rc != 0 )
                        fprintf ( stderr, "failed to access column name [ %u ] for tbl '%s.%s'\n", i, argv [ 1 ], tblname );
                    else
                    {
                        dump_col_name ( tbl, argv [ 1 ], tblname, name );
                    }
                }
            }

            KNamelistRelease ( names );
        }
    }
}
Example #24
0
static rc_t matcher_read_col_src_types( p_mcol col, 
        const KNamelist *names, const uint32_t dflt_idx, const VSchema *schema )
{
    uint32_t count;
    rc_t rc = KNamelistCount( names, &count );
    if ( rc == 0 )
    {
        uint32_t idx;
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *name;
            rc = KNamelistGet( names, idx, &name );
            if ( rc == 0 )
                rc = matcher_append_type( name, ( idx == dflt_idx ), idx,
                                          schema, &(col->src_types) );
        }
    }
    return rc;
}
Example #25
0
static
rc_t KRepositoryMgrCategoryRepositories ( const KConfigNode *cat,
    KRepCategory category, KRepositoryVector *repositories )
{
    KNamelist *sub_names;
    rc_t rc = KConfigNodeListChildren ( cat, & sub_names );
    if ( rc == 0 )
    {
        uint32_t i, count;
        rc = KNamelistCount ( sub_names, & count );
        for ( i = 0; i < count && rc == 0; ++ i )
        {
            const char *sub_name;
            rc = KNamelistGet ( sub_names, i, & sub_name );
            if ( rc == 0 )
            {
                KRepSubCategory subcategory = krepBadSubCategory;
                if ( strcmp ( "main", sub_name ) == 0 )
                    subcategory = krepMainSubCategory;
                else if ( strcmp ( "aux", sub_name ) == 0 )
                    subcategory = krepAuxSubCategory;
                else if ( strcmp ( "protected", sub_name ) == 0 )
                    subcategory = krepProtectedSubCategory;

                if ( subcategory != krepBadSubCategory )
                {
                    const KConfigNode *sub;
                    rc = KConfigNodeOpenNodeRead ( cat, & sub, sub_name );
                    if ( rc == 0 )
                    {
                        rc = KRepositoryMgrSubCategoryRepositories ( sub, category, subcategory, repositories );
                        KConfigNodeRelease ( sub );
                    }
                }
            }
        }

        KNamelistRelease ( sub_names );
    }

    return rc;
}
Example #26
0
bool nlt_is_name_in_namelist( const KNamelist *list, const char *name_to_find )
{
    uint32_t count, idx;
    bool res = false;
    if ( list == NULL || name_to_find == NULL )
        return res;
    if ( KNamelistCount( list, &count ) == 0 )
    {
        for ( idx = 0; idx < count && res == false; ++idx )
        {
            const char *item_name;
            if ( KNamelistGet( list, idx, &item_name ) == 0 )
            {
                if ( nlt_strcmp( item_name, name_to_find ) == 0 )
                    res = true;
            }
        }
    }
    return res;
}
Example #27
0
bool nlt_namelist_is_sub_set_in_full_set( const KNamelist * sub_set, const KNamelist * full_set )
{
    bool res = false;
    uint32_t count;
    rc_t rc = KNamelistCount( sub_set, &count );
    if ( rc == 0 )
    {
        uint32_t idx;
        uint32_t found = 0;
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *s;
            rc = KNamelistGet( sub_set, idx, &s );
            if ( rc == 0 && s != NULL && nlt_is_name_in_namelist( full_set, s ) )
                found++;
        }
        res = ( rc == 0 && count == found );
    }
    return res;
}
Example #28
0
static rc_t matcher_read_dst_types( matcher* self, const VTable *table,
                             const VSchema *schema )
{
    rc_t rc = 0;
    uint32_t idx, len;

    if ( self == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( table == NULL || schema == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );
    len = VectorLength( &(self->mcols) );
    for ( idx = 0;  idx < len && rc == 0; ++idx )
    {
        p_mcol item = (p_mcol) VectorGet ( &(self->mcols), idx );
        if ( item != NULL )
        {
            KNamelist *names;
            rc = VTableListWritableDatatypes ( (VTable*)table, item->name, &names );
            if ( rc == 0 )
            {
                uint32_t type_count;
                rc = KNamelistCount( names, &type_count );
                if ( rc == 0 && type_count > 0 )
                {
                    uint32_t type_idx;
                    item->to_copy = true; /* !!! this column has to be copied */
                    for ( type_idx = 0; type_idx < type_count && rc == 0; ++type_idx )
                    {
                        const char *name;
                        rc = KNamelistGet( names, type_idx, &name );
                        if ( rc == 0 )
                            rc = matcher_append_type( name, false, idx,
                                                      schema, &(item->dst_types) );
                    }
                }
                KNamelistRelease( names );
            }
        }
    }
    return rc;
}
Example #29
0
static rc_t redactable_types_2_type_id_vector( const VSchema * s,
                                               const char * redactable_types,
                                               Vector * id_vector )
{
    const KNamelist *r_types;
    rc_t rc;
    if ( redactable_types == NULL || s == NULL || id_vector == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &r_types, redactable_types );
    if ( rc == 0 )
    {
        uint32_t count, idx;

        rc = KNamelistCount( r_types, &count );
        if ( rc == 0 && count > 0 )
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *name;
                rc = KNamelistGet( r_types, idx, &name );
                if ( rc == 0 )
                {
                    VTypedecl td;
                    rc = VSchemaResolveTypedecl ( s, &td, "%s", name );
                    if ( rc == 0 )
                    {
                        uint32_t *id = malloc( sizeof *id );
                        if ( id != NULL )
                        {
                            *id = td.type_id;
                            rc = VectorAppend ( id_vector, NULL, id );
                        }
                        else
                            rc = RC( rcExe, rcNoTarg, rcResolving, rcMemory, rcExhausted );
                    }
                }
            }
        KNamelistRelease( r_types );
    }
    return rc;
}
Example #30
0
static rc_t copy_metadata_root ( const KMDataNode *src_root, KMDataNode *dst_root,
                                 const char * excluded_nodes,
                                 const bool show_meta )
{
    KNamelist *names;
    const KNamelist *excluded_names = NULL;
    uint32_t i, count;

    rc_t rc = KMDataNodeListChild ( src_root, & names );
    DISP_RC( rc, "copy_metadata_root:KMDataNodeListChild() failed" );
    if ( rc != 0 ) return rc;
    
    if ( excluded_nodes != NULL )
    {
        rc = nlt_make_namelist_from_string( &excluded_names, excluded_nodes );
        DISP_RC( rc, "copy_metadata_root:nlt_make_namelist_from_string() failed" );
        if ( rc != 0 ) return rc;
    }

    rc = KNamelistCount ( names, & count );
    for ( i = 0; rc == 0 && i < count; ++ i )
    {
        const char *node_path;
        rc = KNamelistGet ( names, i, & node_path );
        DISP_RC( rc, "copy_metadata_root:KNamelistGet() failed" );
        if ( rc == 0 )
        {
            bool is_excluded = false;
            if ( excluded_names != NULL )
                is_excluded = nlt_is_name_in_namelist( excluded_names, node_path );
            if ( !is_excluded )
                rc = copy_metadata_child ( src_root, dst_root, node_path, show_meta );
        }
    }

    if ( excluded_names != NULL )
        KNamelistRelease( excluded_names );
    KNamelistRelease ( names );
    return rc;
}