Example #1
0
rc_t copy_table_meta ( const VTable *src_table, VTable *dst_table,
                       const char * excluded_nodes,
                       const bool show_meta, const bool schema_updated )
{
    const KMetadata *src_meta;
    rc_t rc;

    if ( src_table == NULL || dst_table == NULL )
        return RC( rcExe, rcNoTarg, rcCopying, rcParam, rcNull );
    /* it is OK if excluded_nodes is NULL */
    
    rc = VTableOpenMetadataRead ( src_table, & src_meta );
    DISP_RC( rc, "copy_table_meta:VTableOpenMetadataRead() failed" );
    if ( rc == 0 )
    {
        rc = copy_back_revisions ( src_meta, dst_table, show_meta );
        if ( rc == 0 )
        {
            KMetadata *dst_meta;
            rc = VTableOpenMetadataUpdate ( dst_table, & dst_meta );
            DISP_RC( rc, "copy_table_meta:VTableOpenMetadataUpdate() failed" );
            if ( rc == 0 )
            {
                if ( show_meta )
                    KOutMsg( "+++copy current metadata\n" );

                rc = copy_stray_metadata ( src_meta, dst_meta, excluded_nodes,
                                           show_meta );
                if ( show_meta )
                    KOutMsg( "+++end of copy current metadata\n" );

                /* enter a attribute "vdb-copy" under '/SOFTWARE/update'
                   *if the schema was updated ! */
                if ( rc == 0 && schema_updated )
                    rc = enter_schema_update( dst_meta, show_meta );

                /* enter a unconditional node under '/SOFTWARE/Copy'
                    <%TIMESTAMP%>
                        <Application date="%DATE%" name="vdb-copy" vers="%VERSION%"/>
                    </%TIMESTAMP%>
                */
                if ( rc == 0 )
                    rc = enter_vdbcopy_node( dst_meta, show_meta );

                KMetadataRelease ( dst_meta );
            }
        }
        KMetadataRelease ( src_meta );
    }
    return rc;
}
Example #2
0
static uint32_t get_child_count( KMDataNode *node )
{
    uint32_t res = 0;
    KNamelist *names;
    rc_t rc = KMDataNodeListChild ( node, &names );
    DISP_RC( rc, "get_child_count:KMDataNodeListChild() failed" );
    if ( rc == 0 )
    {
        rc = KNamelistCount ( names, &res );
        DISP_RC( rc, "get_child_count:KNamelistCount() failed" );
        KNamelistRelease ( names );
    }
    return res;
}
Example #3
0
static void setup_compress_context( const Args * args, p_compress_context ctx )
{
    uint32_t count;
    const char *value = NULL;
    rc_t rc = ArgsParamCount( args, &count );
    DISP_RC( rc, "ArgsParamCount() failed" );
    if ( rc == 0 )
    {
        rc = ArgsParamValue( args, 0, &value );
        DISP_RC( rc, "ArgsParamValue() failed" );
        if ( rc == 0 )
            ctx->src_file = string_dup_measure( value, NULL );

        rc = ArgsParamValue( args, 1, &value );
        DISP_RC( rc, "ArgsParamValue() failed" );
        if ( rc == 0 )
            ctx->dst_file = string_dup_measure( value, NULL );
    }

    value = get_str_option( args, OPTION_DIRECTION );
    if ( value )
    {
        switch ( value[0] )
        {
        case 'c' :
        case 'C' : ctx->direction = KC_COMPRESS; break;
        case 'd' :
        case 'D' : ctx->direction = KC_DECOMPRESS; break;
        }
    }
    if ( ctx->direction == 0 )
        ctx->direction = KC_DECOMPRESS;

    value = get_str_option( args, OPTION_METHOD );
    if ( value )
    {
        switch ( value[0] )
        {
        case 'g' :
        case 'G' : ctx->method = KC_GZIP; break;
        case 'b' :
        case 'B' : ctx->method = KC_BZIP; break;
        case 's' :
        case 'S' : ctx->method = KC_SZIP; break;
        }
    }
    if ( ctx->method == 0 )
        ctx->method = KC_GZIP;
}
Example #4
0
static rc_t CC scan_mod_dir(const KDirectory* dir,
    uint32_t type, const char* name, void* data)
{
    rc_t rc = 0;
    const char ext[] = SHLX;

    assert(data);

    if (strlen(name) > strlen(ext) + 1 &&
        name[strlen(name) - strlen(ext) - 1] == '.')
    {
        char buf[PATH_MAX + 1];
        rc = KDirectoryResolvePath
            (dir, true, buf, sizeof buf, "%s/%s", data, name);

        while (rc == 0) {
            uint32_t type = KDirectoryPathType(dir, buf);
            if (type & kptAlias) {
                rc = KDirectoryResolveAlias
                    (dir, true, buf, sizeof buf, buf);
                DISP_RC(rc, name);
            }
            else if (rc == 0) {
                if (type == kptNotFound || type == kptBadPath) {
                    OUTMSG(("%s: %s\n", buf,
                        type == kptNotFound ? "not found" : "bad path"));
                }
                else { OUTMSG(("%s\n", buf)); }
                break;
            }
        }
    }

    return rc;
}
Example #5
0
static rc_t XmlMetaInit(rc_t rc, XmlMeta* meta,
    const AppCtx* ctx, const char* xml)
{
    const KFile* f = NULL;
    const KXMLDoc* doc = NULL;
    const KXMLNodeset* ns = NULL;
    const KXMLNode* node = NULL;
    const char path[] = "/Run";
    memset(meta, 0, sizeof *meta);
    if (rc) {
        return rc;
    }
    if (rc == 0) {
        rc = KDirectoryOpenFileRead(ctx->dir, &f, xml);
        DISP_RC(rc, xml);
    }
    if (rc == 0) {
        rc = KXMLMgrMakeDocRead(ctx->x_mgr, &doc, f);
        DISP_RC(rc, xml);
    }
    if (rc == 0) {
        rc = KXMLDocOpenNodesetRead(doc, &ns, path);
        DISP_RC(rc, path);
    }
    if (rc == 0) {
        rc = KXMLNodesetGetNodeRead(ns, &node, 0);
        DISP_RC(rc, path);
    }
    if (rc == 0) {
        rc = ParseSraMetaNode(node, path, NULL, &meta->root);
    }
    if (rc == 0 && !meta->root.found) {
        meta->tr = calloc(1, sizeof *meta->tr);
        if (meta->tr == NULL) {
            rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted);
        }
        else {
            BSTreeInit(meta->tr);
            rc = XmlMetaInitMembers(meta->tr, node);
        }
    }
    RELEASE(KXMLNode, node);
    RELEASE(KXMLNodeset, ns);
    RELEASE(KXMLDoc, doc);
    RELEASE(KFile, f);
    return rc;
}
static void CC vdcd_reset_1_content( void *item, void *data )
{
    rc_t rc;
    p_col_def my_col_def = (p_col_def)item;
    if ( my_col_def == NULL ) return;
    rc = vds_clear( &(my_col_def->content) );
    DISP_RC( rc, "dump_str_clear() failed" );
}
Example #7
0
/*
 * walks through the column-definitions and if a column
 * has the to_copy-flag set, and it's name is in the
 * given list of column-names the to copy-flag is cleared
 * does not require an open cursor.
*/
rc_t col_defs_exclude_these_columns( col_defs* defs, const char * prefix, const char * column_names )
{
    rc_t rc = 0;
    const KNamelist *names;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    /* it is OK if we have not column-names to exclude */
    if ( column_names == NULL )
        return 0;
    if ( column_names[0] == 0 )
        return 0;

    rc = nlt_make_namelist_from_string( &names, column_names );
    DISP_RC( rc, "col_defs_parse_string:nlt_make_namelist_from_string() failed" );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        size_t prefix_len = 0;
        if ( prefix != 0 )
            prefix_len = string_size( prefix ) + 2;
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
            {
                if ( col->requested )
                {
                    if ( nlt_is_name_in_namelist( names, col->name ) )
                        col->requested = false;
                    else
                    {
                        if ( prefix != NULL )
                        {
                            size_t len1 = string_size ( col->name ) + prefix_len;
                            char * s = malloc( len1 );
                            if ( s != NULL )
                            {
                                size_t num_writ;
                                rc_t rc1 = string_printf ( s, len1, &num_writ, "%s:%s", prefix, col->name );
                                if ( rc1 == 0 )
                                {
                                    if ( nlt_is_name_in_namelist( names, s ) )
                                        col->requested = false;
                                }
                                free( s );
                            }
                        }
                    }
                }
            }
        }
        KNamelistRelease( names );
    }
    return rc;
}
Example #8
0
static rc_t copy_back_revisions ( const KMetadata *src_meta, VTable *dst_table,
                                  const bool show_meta )
{
    uint32_t max_revision, revision;

    rc_t rc = KMetadataMaxRevision ( src_meta, &max_revision );
    DISP_RC( rc, "copy_back_revisions:KMetadataMaxRevision() failed" );
    if ( rc != 0 ) return rc;
    if ( max_revision == 0 ) return rc;
    for ( revision = 1; revision <= max_revision && rc == 0; ++revision )
    {
        const KMetadata *src_rev_meta;

        if ( show_meta )
            KOutMsg( "+++copy metadata rev. #%u:\n", revision );
        rc = KMetadataOpenRevision ( src_meta, &src_rev_meta, revision );
        DISP_RC( rc, "copy_back_revisions:KMetadataOpenRevision() failed" );
        if ( rc == 0 )
        {
            KMetadata *dst_meta;
            rc = VTableOpenMetadataUpdate ( dst_table, & dst_meta );
            DISP_RC( rc, "copy_table_meta:VTableOpenMetadataUpdate() failed" );
            if ( rc == 0 )
            {
                rc = copy_stray_metadata ( src_rev_meta, dst_meta, NULL, show_meta );
                if ( rc == 0 )
                {
                    rc = KMetadataCommit ( dst_meta );
                    DISP_RC( rc, "copy_back_revisions:KMetadataCommit() failed" );
                    if ( rc == 0 )
                    {
                        rc = KMetadataFreeze ( dst_meta );
                        DISP_RC( rc, "copy_back_revisions:KMetadataFreeze() failed" );
                    }
                }
                KMetadataRelease ( dst_meta );
            }

            KMetadataRelease ( src_rev_meta );
        }
    }
    return rc;
}
/** Init the static directory object */
static rc_t SpotIteratorInitDirectory(void) {
    if (__SpotIteratorDirectory) {
        return 0;
    }
    else {
        rc_t rc = KDirectoryNativeDir(&__SpotIteratorDirectory);
        DISP_RC(rc, "while calling KDirectoryNativeDir");
        return rc;
    }
}
Example #10
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 #11
0
static rc_t AppCtxInit(rc_t rc, AppCtx* ctx) {
    assert(ctx);
    memset(ctx, 0 , sizeof *ctx);
    if (rc) {
        return rc;
    }
    if (rc == 0) {
        rc = SRAMgrMakeUpdate(&ctx->s_mgr, NULL);
        DISP_RC(rc, "while calling SRAMgrMakeUpdate");
    }
    if (rc == 0) {
        rc = KXMLMgrMakeRead(&ctx->x_mgr);
        DISP_RC(rc, "while calling KXMLMgrMakeRead");
    }
    if (rc == 0) {
        rc = KDirectoryNativeDir(&ctx->dir);
        DISP_RC(rc, "while calling KDirectoryNativeDir");
    }
    return rc;
}
Example #12
0
static rc_t enter_version( KMDataNode *node, const char * key )
{
    char buff[ 32 ];
    rc_t rc;

    rc = string_printf ( buff, sizeof( buff ), NULL, "%.3V", VDB_COPY_VERS );
    assert ( rc == 0 );
    rc = KMDataNodeWriteAttr ( node, key, buff );
    DISP_RC( rc, "enter_version:KMDataNodeWriteAttr() failed" );
    return rc;
}
Example #13
0
static rc_t enter_time( KMDataNode *node, const char * key )
{
    char timestring[ 160 ];
    rc_t rc = fill_timestring( timestring, sizeof timestring );
    if ( rc == 0 )
    {
        rc = KMDataNodeWriteAttr ( node, key, timestring );
        DISP_RC( rc, "enter_time:KMDataNodeWriteAttr( timestring ) failed" );
    }
    return rc;
}
Example #14
0
static rc_t ShowModDir(const KDirectory* native, char* path) {
    rc_t rc = 0;
    const KDirectory* dir = NULL;
    assert(native && path);
    rc = KDirectoryOpenDirRead(native, &dir, false, path);
    DISP_RC(rc, path);
    if (rc == 0) {
        rc = KDirectoryVVisit(dir, false, scan_mod_dir, path, ".", NULL);
    }
    return rc;
}
Example #15
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 #16
0
static rc_t vdb_fastq_database( const p_dump_context ctx,
                                const VDBManager *mgr,
                                fastq_ctx * fctx )
{
    const VDatabase * db;
    VSchema *schema = NULL;
    rc_t rc;

    vdh_parse_schema( mgr, &schema, &(ctx->schema_list) );

    rc = VDBManagerOpenDBRead( mgr, &db, schema, ctx->path );
    DISP_RC( rc, "VDBManagerOpenDBRead() failed" );
    if ( rc == 0 )
    {
        bool table_defined = ( ctx->table != NULL );
        if ( !table_defined )
            table_defined = vdh_take_this_table_from_db( ctx, db, "SEQUENCE" );

        if ( table_defined )
        {
            const VTable * tbl;

            rc = VDatabaseOpenTableRead( db, &tbl, ctx->table );
            DISP_RC( rc, "VDatabaseOpenTableRead() failed" );
            if ( rc == 0 )
            {
                rc = vdb_fastq_tbl( ctx, tbl, fctx );
                VTableRelease( tbl );
            }
        }
        else
        {
            LOGMSG( klogInfo, "opened as vdb-database, but no table found/defined" );
            ctx->usage_requested = true;
        }
        VDatabaseRelease( db );
    }

    VSchemaRelease( schema );
    return rc;
}
Example #17
0
static rc_t bam_header(const VDatabase* db) {
    rc_t rc = 0;
    const char path[] = "BAM_HEADER";
    const KMetadata* meta = NULL;
    const KMDataNode* node = NULL;
    char* buffer = NULL;
    assert(db);
    if (rc == 0) {
        rc = VDatabaseOpenMetadataRead(db, &meta);
        DISP_RC(rc, "while calling VDatabaseOpenMetadataRead");
    }
    if (rc == 0) {
        rc = KMetadataOpenNodeRead(meta, &node, "%s", path);
        if (GetRCState(rc) == rcNotFound)
        {   rc = 0; }
        else {
            DISP_RC2(rc, path, "while calling KMetadataOpenNodeRead");
            if (rc == 0) {
                int i = 0;
                size_t bsize = 0;
                size_t size = 1024;
                for (i = 0; i < 2; ++i) {
                    free(buffer);
                    bsize = size + 1;
                    buffer = malloc(bsize);
                    if (buffer == NULL) {
                        rc = RC(rcExe, rcStorage, rcAllocating,
                            rcMemory, rcExhausted);
                    }
                    else {
                        rc = KMDataNodeReadCString(node, buffer, bsize, &size);
                        if (rc == 0) {
                            break;
                        }
                        else if (i == 0
                            && GetRCObject(rc) == (enum RCObject)rcBuffer
                            && GetRCState (rc) ==          rcInsufficient)
                        {
                            rc = 0;
                        }
                    }
                    DISP_RC2(rc, path, "while calling KMDataNodeReadCString");
                }
            }
        }
    }
    if (rc == 0 && buffer)
    {   OUTMSG(("BAM_HEADER: {\n%s}\n\n", buffer)); }
    DESTRUCT(KMDataNode, node);
    DESTRUCT(KMetadata, meta);
    free(buffer);
    return rc;
}
Example #18
0
static rc_t enter_date_name_vers( KMDataNode *node )
{
    rc_t rc = enter_time( node, "run" );
    DISP_RC( rc, "enter_date_name_vers:enter_time() failed" );
    if ( rc == 0 )
    {
        rc = KMDataNodeWriteAttr ( node, "tool", "vdb-copy" );
        DISP_RC( rc, "enter_date_name_vers:KMDataNodeWriteAttr(tool=vdb-copy) failed" );
        if ( rc == 0 )
        {
            rc = enter_version ( node, "vers" );
            DISP_RC( rc, "enter_date_name_vers:enter_version() failed" );
            if ( rc == 0 )
            {
                rc = KMDataNodeWriteAttr ( node, "build", __DATE__ );
                DISP_RC( rc, "enter_date_name_vers:KMDataNodeWriteAttr(build=_DATE_) failed" );
            }
        }
    }
    return rc;
}
Example #19
0
static rc_t XmlMetaInitMembers(BSTree* tr, const KXMLNode* node) {
    rc_t rc = 0;
    const char path[] = "Member";
    uint32_t count = 0;
    uint32_t idx = 0;
    const KXMLNodeset *members = NULL;
    if (rc == 0) {
        rc = KXMLNodeOpenNodesetRead(node, &members, path);
        DISP_RC(rc, path);
    }
    if (rc == 0) {
        rc = KXMLNodesetCount(members, &count);
        DISP_RC(rc, path);
    }
    for (idx = 0; idx < count && rc == 0; ++idx) {
        const KXMLNode *node = NULL;
        char member_name[256] = "";
        if (rc == 0) {
            rc = KXMLNodesetGetNodeRead(members, &node, idx);
            DISP_RC(rc, path);
        }
        if (rc == 0) {
            size_t size = 0;
            rc = KXMLNodeReadAttrCString(node, "member_name",
                member_name, sizeof member_name, &size);
            if (rc) {
                if (GetRCState(rc) == rcInsufficient) {
                    member_name[sizeof member_name - 1] = '\0';
                    rc = 0;
                }
            }
        }
        if (rc == 0) {
            rc = XmlMetaInitMemser(tr, node, path, member_name);
        }
        RELEASE(KXMLNode, node);
    }
    RELEASE(KXMLNodeset, members);
    return rc;
}
Example #20
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;
}
Example #21
0
rc_t CC KMain(int argc, char* argv[]) {
    rc_t rc = 0;

    Params prm;
    KConfig* cfg = NULL;

    if (rc == 0)
    {   rc = ParamsConstruct(argc, argv, &prm); }

    if (rc == 0) {
        rc = KConfigMake(&cfg, NULL);
        DISP_RC(rc, "while calling KConfigMake");
    }

    if (rc == 0) {
        if (prm.modeSetNode)
        {   rc = SetNode(cfg, &prm); }
        if (prm.modeShowCfg)
        {   rc = ShowConfig(cfg, &prm); }
        if (prm.modeShowFiles) {
            rc_t rc3 = ShowFiles(cfg, &prm);
            if (rc3 != 0 && rc == 0)
            {   rc = rc3; }
        }
        if (prm.modeShowModules) {
            rc_t rc3 = ShowModules(cfg, &prm);
            if (rc3 != 0 && rc == 0)
            {   rc = rc3; }
        }
        if (prm.modeShowLoadPath) {
            const char* path = NULL;
            rc_t rc3 = KConfigGetLoadPath(cfg, &path);
            if (rc3 == 0) {
                if (path != NULL && path[0])
                {   OUTMSG(("%s\n", path)); }
            }
            else if (rc == 0)
            {   rc = rc3; }
        }
    }

    if (prm.modeShowEnv)
    {   ShowEnv(&prm); }

    RELEASE(KConfig, cfg);

    if (rc == 0 && prm.modeCreate)
    {   rc = CreateConfig(argv[0]); }

    ParamsDestruct(&prm);
    return rc;
}
Example #22
0
static
rc_t privReadStdinLine(char* buf, size_t bsize, bool destroy)
{
    rc_t rc = 0;
    static const KFile* std_in = NULL;
    static uint64_t pos = 0;
    size_t num_read = 0;
    if (destroy) {
        RELEASE(KFile, std_in);
        pos = 0;
        return rc;
    }
    if (std_in == NULL) {
        rc = KFileMakeStdIn(&std_in);
        if (rc != 0) {
            DISP_RC(rc, "KFileMakeStdIn");
            return rc;
        }
    }
    rc = KFileRead(std_in, pos, buf, bsize, &num_read);
    DISP_RC(rc, "KFileRead");
    pos += num_read;
    if (num_read) {
        bool done = false;
        buf[num_read] = '\0';
        while (num_read > 0 && !done) {
            switch (buf[num_read - 1]) {
                case '\n':
                case '\r':
                    buf[--num_read] = '\0';
                    break;
                default:
                    done = true;
                    break;
            }
        }
    }
    return rc;
}
Example #23
0
static rc_t copy_metadata_data ( const KMDataNode *snode, KMDataNode *dnode )
{
    char buffer [ 1024 ];
    size_t total, bytes, remaining;
    /* copy node data unless already set */
    rc_t rc = KMDataNodeRead ( dnode, 0, buffer, 0, & bytes, & total );
    DISP_RC( rc, "copy_metadata_child:KMDataNodeRead(dst) failed" );
    if ( rc == 0 && total == 0 )
    do
    {
        rc = KMDataNodeRead ( snode, total, buffer, sizeof buffer, & bytes, & remaining );
        DISP_RC( rc, "copy_metadata_child:KMDataNodeRead(src) failed" );
        if ( rc == 0 )
        {
            rc = KMDataNodeAppend ( dnode, buffer, bytes );
            DISP_RC( rc, "copy_metadata_child:KMDataNodeAppend(dst) failed" );
            if ( rc != 0 ) break;
        }
        total += bytes;
     } while ( remaining != 0 );
    return rc;
}
Example #24
0
static rc_t vdb_prepare_cursor( const p_dump_context ctx, const VTable * tbl, fastq_ctx * fctx )
{
    rc_t rc;

    /* first we try to open READ/QUALITY/NAME */
    rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
    DISP_RC( rc, "VTableCreateCursorRead( 1st ) failed" );
    if ( rc == 0 )
    {
        rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
        if ( rc == 0 && ctx->format == df_fastq )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
        else
            fctx->idx_qual = INVALID_COLUMN;
        if ( rc == 0 )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_name, "(ascii)NAME" );
        if ( rc == 0 )
            rc = VCursorOpen ( fctx->cursor );

        if ( rc != 0 )
        {
            VCursorRelease( fctx->cursor );
            rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
            DISP_RC( rc, "VTableCreateCursorRead( 2nd ) failed" );
            if ( rc == 0 )
            {
                rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
                if ( rc == 0 && ctx->format == df_fastq )
                    rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
                else
                    fctx->idx_qual = INVALID_COLUMN;
                if ( rc == 0 )
                    rc = VCursorOpen ( fctx->cursor );
                fctx->idx_name = INVALID_COLUMN;
            }
        }
    }
    return rc;
}
Example #25
0
static rc_t SetNode(KConfig* cfg, const Params* prm) {
    rc_t rc = 0;

    KConfigNode* node = NULL;
    char* name = NULL;
    char* val  = NULL;

    assert(cfg && prm && prm->setValue);

    name = strdup(prm->setValue);
    if (name == NULL)
    {   return RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); }

    val = strchr(name, '=');
    if (val == NULL || *(val + 1) == '\0') {
        rc_t rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcInvalid);
        LOGERR(klogErr, rc, "Bad " OPTION_SET " value");
    }

    if (rc == 0) {
        *(val++) = '\0';

        rc = KConfigOpenNodeUpdate(cfg, &node, name);
        if (rc != 0) {
            PLOGERR(klogErr, (klogErr, rc,
                "Cannot open node '$(name)' for update", "name=%s", name));
        }
    }

    if (rc == 0) {
        assert(val);
        rc = KConfigNodeWrite(node, val, strlen(val));
        if (rc != 0) {
            PLOGERR(klogErr, (klogErr, rc,
                "Cannot write value '$(val) to node '$(name)'",
                "val=%s,name=%s", val, name));
        }
    }

    if (rc == 0) {
        rc = KConfigCommit(cfg);
        DISP_RC(rc, "while calling KConfigCommit");
    }

    free(name);
    name = NULL;

    RELEASE(KConfigNode, node);
    return rc;
}
Example #26
0
/********************************************************************
helper function to display the version of the vdb-manager
********************************************************************/
rc_t vdh_show_manager_version( const VDBManager *my_manager )
{
    uint32_t version;
    rc_t rc = VDBManagerVersion( my_manager, &version );
    DISP_RC( rc, "VDBManagerVersion() failed" );
    if ( rc == 0 )
    {
        PLOGMSG ( klogInfo, ( klogInfo, "manager-version = $(maj).$(min).$(rel)",
                              "vers=0x%X,maj=%u,min=%u,rel=%u",
                              version,
                              version >> 24,
                              ( version >> 16 ) & 0xFF,
                              version & 0xFFFF ));
    }
Example #27
0
static rc_t copy_stray_metadata ( const KMetadata *src_meta, KMetadata *dst_meta,
                                  const char * excluded_nodes,
                                  const bool show_meta )
{
    /* open root node */
    const KMDataNode *src_root;
    rc_t rc = KMetadataOpenNodeRead ( src_meta, & src_root, NULL );
    DISP_RC( rc, "copy_stray_metadata:KMetadataOpenNodeRead() failed" );
    if ( rc == 0 )
    {
        KMDataNode *dst_root;
        rc = KMetadataOpenNodeUpdate ( dst_meta, & dst_root, NULL );
        DISP_RC( rc, "copy_stray_metadata:KMetadataOpenNodeUpdate() failed" );
        if ( rc == 0 )
        {
            /* treat the root node in a special way */
            rc = copy_metadata_root ( src_root, dst_root, excluded_nodes, show_meta );
            KMDataNodeRelease ( dst_root );
        }
        KMDataNodeRelease ( src_root );
    }
    return rc;
}
Example #28
0
static rc_t enter_schema_update( KMetadata *dst_meta, const bool show_meta )
{
    rc_t rc;
    KMDataNode *sw_node;

    if ( show_meta )
        KOutMsg( "--- entering schema-update\n" );

    rc = KMetadataOpenNodeUpdate ( dst_meta, &sw_node, "SOFTWARE" );
    DISP_RC( rc, "enter_schema_update:KMetadataOpenNodeUpdate('SOFTWARE') failed" );
    if ( rc == 0 )
    {
        KMDataNode *update_node;
        rc = KMDataNodeOpenNodeUpdate ( sw_node, &update_node, "update" );
        DISP_RC( rc, "enter_schema_update:KMDataNodeOpenNodeUpdate('update') failed" );
        if ( rc == 0 )
        {
            rc = enter_date_name_vers( update_node );
            KMDataNodeRelease ( update_node );
        }
        KMDataNodeRelease ( sw_node );
    }
    return rc;
}
Example #29
0
static rc_t fill_timestring( char * s, size_t size )
{
    KTime tr;
    rc_t rc;
    
    KTimeLocal ( &tr, KTimeStamp() );
/*
    rc = string_printf ( s, size, NULL, 
                         "%.04u-%.02u-%.02u %.02u:%.02u:%.02u",
                         tr.year, tr.month + 1, tr.day, tr.hour, tr.minute, tr.second );
*/
    rc = string_printf ( s, size, NULL, "%lT", &tr );

    DISP_RC( rc, "fill_timestring:string_printf( date/time ) failed" );
    return rc;
}
Example #30
0
static rc_t init_ictx( struct ictx * ictx, const dump_context * ctx, const Args * args )
{
    rc_t rc = KFileMakeStdIn ( &( ictx->std_in ) );
    DISP_RC( rc, "KFileMakeStdIn() failed" );
    if ( rc == 0 )
    {
        ictx->ctx = ctx;
        ictx->args = args;
        VectorInit( &ictx->history, 0, 10 );
        ictx->interactive = ( KFileType ( ictx->std_in ) == kfdCharDev );
        ictx->done = false;
        
        CONST_STRING( &(ictx->PROMPT), "\nvdb $" );
        StringInit( &(ictx->SInputLine), &( ictx->inputline[0] ), sizeof( ictx->inputline ), 0 );
        
        rc = vdp_init_ctx( &ictx->vsctx, args );
    }
    return rc;
}