rc_t make_column_namelist ( const BSTree *columns, KNamelist **names ) { VNamelist *list; rc_t rc = VNamelistMake ( & list, 8 ); if ( rc == 0 ) { const String *last = NULL; const VColumnRef *cref = ( const VColumnRef* ) BSTreeFirst ( columns ); while ( cref != NULL ) { if ( last == NULL || ! StringEqual ( last, & cref -> name ) ) { rc = VNamelistAppend ( list, cref -> name . addr ); if ( rc != 0 ) break; last = & cref -> name; } cref = ( const VColumnRef* ) BSTNodeNext ( & cref -> n ); } if ( rc == 0 ) rc = VNamelistToNamelist ( list, names ); VNamelistRelease ( list ); } return rc; }
rc_t register_temp_file( temp_registry * self, uint32_t read_id, const char * filename ) { rc_t rc = 0; if ( self == NULL ) rc = RC( rcVDB, rcNoTarg, rcConstructing, rcSelf, rcNull ); else if ( filename == NULL ) rc = RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull ); else { rc = KLockAcquire ( self -> lock ); if ( rc == 0 ) { VNamelist * l = VectorGet ( &self -> lists, read_id ); if ( l == NULL ) { rc = VNamelistMake ( &l, 12 ); if ( rc == 0 ) { rc = VectorSet ( &self -> lists, read_id, l ); if ( rc != 0 ) VNamelistRelease ( l ); } } if ( rc == 0 && l != NULL ) { rc = VNamelistAppend ( l, filename ); if ( rc == 0 ) rc = Add_File_to_Cleanup_Task ( self -> cleanup_task, filename ); } KLockUnlock ( self -> lock ); } } return rc; }
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; }
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; }
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; }
rc_t add_cgi_request_param( struct cgi_request * request, const char * fmt, ... ) { rc_t rc; if ( request == NULL || fmt == NULL ) rc = RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull ); else { va_list args; char buffer[ 4096 ]; size_t num_writ; va_start ( args, fmt ); rc = string_vprintf( buffer, sizeof buffer, &num_writ, fmt, args ); if ( rc != 0 ) ErrMsg( "string_vprintf( '%s' ) -> %R", fmt, rc ); else { DBGMSG ( DBG_APP, DBG_FLAG ( DBG_APP_1 ), ( "\t%s\n", buffer ) ); rc = VNamelistAppend( request->params, buffer ); if ( rc != 0 ) ErrMsg( "VNamelistAppend( '%s' ) -> %R", buffer, rc ); } va_end ( args ); } return rc; }
rc_t ref_walker_add_source( struct ref_walker * self, const char * src ) { rc_t rc = 0; if ( self == NULL ) rc = RC( rcApp, rcNoTarg, rcConstructing, rcParam, rcNull ); else rc = VNamelistAppend ( self->sources, src ); return rc; }
static rc_t add_tool_options_path( tool_options * options, const char * path ) { rc_t rc = VNamelistAppend ( options->paths, path ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "VNamelistAppend( $(name) ) failed in $(func)", "name=%s, func=%s", path, __func__ ) ); } if ( rc == 0 ) options->path_count++; return rc; }
static bool CC list_dylib ( void *item, void *data ) { size_t bytes; char utf8 [ 4096 ], *p; list_dylib_param *pb = data; const KDylib *lib = ( const void* ) item; /* "lib" was created with KDylibMake which creates a NUL terminated path. of course, this could seg-fault if bad... */ assert ( lib -> path . addr [ lib -> path . len ] == 0 ); /* convert wide-character to UTF-8 */ bytes = wchar_cvt_string_copy ( utf8, sizeof utf8, lib -> path . addr, lib -> path . size ); if ( bytes < sizeof utf8 ) { pb -> rc = VNamelistAppend ( pb -> list, utf8 ); return pb -> rc != 0; } p = malloc ( 16 * 1024 ); if ( p == NULL ) { pb -> rc = RC ( rcFS, rcDylib, rcListing, rcMemory, rcExhausted ); return true; } bytes = wchar_cvt_string_copy ( p, 16 * 1024, lib -> path . addr, lib -> path . size ); if ( bytes >= 16 * 1024 ) pb -> rc = RC ( rcFS, rcDylib, rcListing, rcPath, rcTooLong ); else pb -> rc = VNamelistAppend ( pb -> list, p ); free ( p ); return pb -> rc != 0; }
rc_t report_set_columns( p_report self, size_t count, ... ) { rc_t rc; if ( self != NULL ) { VNamelistRelease ( self->columns ); /* ignores NULL */ rc = VNamelistMake ( &self->columns, count ); if ( rc == 0 ) { self->col_count = count; if ( self->max_width != NULL ) free( self->max_width ); self->max_width = malloc( count * sizeof( *self->max_width ) ); if ( self->max_width == NULL ) rc = RC( rcExe, rcNoTarg, rcConstructing, rcMemory, rcExhausted ); if ( rc == 0 ) { size_t idx; va_list args; va_start ( args, count ); for ( idx = 0; idx < count && rc == 0; ++idx ) { const char * s = va_arg( args, const char * ); if ( s != NULL ) { rc = VNamelistAppend ( self->columns, s ); self->max_width[ idx ] = string_size( s ); } else { rc = VNamelistAppend ( self->columns, "." ); self->max_width[ idx ] = 1; } } va_end ( args ); }
static bool CC list_dylib ( void *item, void *data ) { list_dylib_param *pb = data; const KDylib *lib = ( const void* ) item; /* "lib" was created with KDylibMake which creates a NUL terminated path. of course, this could seg-fault if bad... */ assert ( lib -> path . addr [ lib -> path . size ] == 0 ); pb -> rc = VNamelistAppend ( pb -> list, lib -> path . addr ); return pb -> rc != 0; }
static void append_str_arguments( const Args *my_args, VNamelist *dst ) { uint32_t count; rc_t rc = ArgsParamCount( my_args, &count ); if ( ( rc == 0 )&&( count > 0 ) ) { uint32_t idx; for ( idx=0; idx<count; ++idx ) { const char* s; if ( ArgsParamValue( my_args, idx, (const void **)&s ) == 0 ) VNamelistAppend( dst, s ); } } }
static void append_str_options( const Args *my_args, const char *name, VNamelist *dst ) { uint32_t count; rc_t rc = ArgsOptionCount( my_args, name, &count ); if ( ( rc == 0 )&&( count > 0 ) ) { uint32_t idx; for ( idx=0; idx<count; ++idx ) { const char* s; if ( ArgsOptionValue( my_args, name, idx, (const void **)&s ) == 0 ) VNamelistAppend( dst, s ); } } }
static rc_t CC _AddTrimStringToList_ZHR ( struct VNamelist * List, char * String ) { /*)) (( We suppose that String is null terminated and editable )) ... i.e. it could be called by Tokenizer only ((*/ char * BG, * EN; if ( String == NULL ) { return 0; } if ( List == NULL ) { return XFS_RC ( rcNull ); } BG = String; EN = BG + strlen ( String ); /*) Trim from front (*/ while ( BG < EN ) { if ( isspace ( * BG ) ) { BG ++; } else { break; } } /*) Trim from end (*/ while ( BG < EN ) { if ( isspace ( * EN ) || * EN == 0 ) { * EN = 0; EN --; } else { break; } } if ( 0 < EN - BG ) { return VNamelistAppend ( List, BG ); } return 0; } /* _AddTrimStringToList_ZHR () */
rc_t make_column_typelist ( const BSTree *columns, const char *col, uint32_t *dflt_idx, KNamelist **typedecls ) { VNamelist *list; rc_t rc = VNamelistMake ( & list, 8 ); if ( rc == 0 ) { uint32_t idx; const VColumnRef *first; String col_name; StringInitCString ( & col_name, col ); first = ( const VColumnRef* ) BSTreeFind ( columns, & col_name, VColumnRefCmpString ); if ( first != NULL ) { const VColumnRef *cref = ( const VColumnRef* ) BSTNodePrev ( & first -> n ); while ( cref != NULL && StringEqual ( & first -> name, & cref -> name ) ) { first = cref; cref = ( const VColumnRef* ) BSTNodePrev ( & cref -> n ); } for ( cref = first, idx = 0; ; ++ idx ) { rc = VNamelistAppend ( list, cref -> typedecl ); if ( rc != 0 ) break; if ( cref -> dflt ) * dflt_idx = idx; cref = ( const VColumnRef* ) BSTNodeNext ( & cref -> n ); if ( cref == NULL || ! StringEqual ( & first -> name, & cref -> name ) ) break; } } if ( rc == 0 ) rc = VNamelistToNamelist ( list, typedecls ); VNamelistRelease ( list ); } return rc; }
static void _ListKeysCallback ( BSTNode * Node, void * Data ) { struct VNamelist * List; struct XFSOwpEntry * TheNode; List = NULL; TheNode = NULL; if ( Node != NULL && Data != NULL ) { List = ( struct VNamelist * ) Data; TheNode = ( struct XFSOwpEntry * ) Node; VNamelistAppend ( List, TheNode -> Key ); } } /* _ListKeysCallback () */
static rc_t extract_spotgroups_from_stats( VNamelist * spotgroups, input_database * id, const KMetadata * meta ) { const KMDataNode * node; rc_t rc = KMetadataOpenNodeRead( meta, &node, "STATS/SPOT_GROUP" ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open meta-node 'STATS/SPOT_GROUP' from '$(t)'", "t=%s", id->path ) ); else { KNamelist * node_childs; rc = KMDataNodeListChildren( node, &node_childs ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot list children of SPOT_GROUP-node in '$(t)'", "t=%s", id->path ) ); else { uint32_t n_count; rc = KNamelistCount( node_childs, &n_count ); if ( rc == 0 && n_count > 0 ) { uint32_t n_idx; for ( n_idx = 0; n_idx < n_count && rc == 0; ++n_idx ) { const char * spotgroup; rc = KNamelistGet( node_childs, n_idx, &spotgroup ); if ( rc == 0 && spotgroup != NULL ) { uint32_t found; rc_t rc1 = VNamelistIndexOf( spotgroups, spotgroup, &found ); if ( GetRCState( rc1 ) == rcNotFound ) rc = VNamelistAppend( spotgroups, spotgroup ); } } } KNamelistRelease( node_childs ); } KMDataNodeRelease( node ); } return rc; }
rc_t nlt_make_namelist_from_string( const KNamelist **list, const char * src ) { VNamelist *v_names; rc_t rc = VNamelistMake ( &v_names, 5 ); if ( rc == 0 ) { char * s = string_dup_measure ( src, NULL ); if ( s ) { uint32_t str_begin = 0; uint32_t str_end = 0; char c; do { c = s[ str_end ]; if ( c == ',' || c == 0 ) { if ( str_begin < str_end ) { char c_temp = c; s[ str_end ] = 0; rc = VNamelistAppend ( v_names, &(s[str_begin]) ); s[ str_end ] = c_temp; } str_begin = str_end + 1; } str_end++; } while ( c != 0 && rc == 0 ); free( s ); } if ( rc == 0 ) rc = VNamelistToConstNamelist ( v_names, list ); VNamelistRelease( v_names ); } return rc; }
static void LoadFromBuffer( VNamelist * nl, buffer_range * range ) { uint32_t idx; const char * p = range->start; String S; S.addr = p; S.len = S.size = range->processed; for ( idx = range->processed; idx < range->count; ++idx ) { switch( p[ idx ] ) { case 0x0A : switch( range->state ) { case STATE_ALPHA : /* ALPHA --> LF */ VNamelistAppendString ( nl, &S ); range->state = STATE_LF; break; case STATE_LF : /* LF --> LF */ VNamelistAppend ( nl, empty_str ); break; case STATE_NL : /* NL --> LF */ VNamelistAppend ( nl, empty_str ); range->state = STATE_LF; break; } break; case 0x0D : switch( range->state ) { case STATE_ALPHA : /* ALPHA --> NL */ VNamelistAppendString ( nl, &S ); range->state = STATE_NL; break; case STATE_LF : /* LF --> NL */ range->state = STATE_NL; break; case STATE_NL : /* NL --> NL */ VNamelistAppend ( nl, empty_str ); break; } break; default : switch( range->state ) { case STATE_ALPHA : /* ALPHA --> ALPHA */ S.len++; S.size++; break; case STATE_LF : /* LF --> ALPHA */ S.addr = &p[ idx ]; S.len = S.size = 1; range->state = STATE_ALPHA; break; case STATE_NL : /* NL --> ALPHA */ S.addr = &p[ idx ]; S.len = S.size = 1; range->state = STATE_ALPHA; break; } break; } } if ( range->state == STATE_ALPHA ) { range->start = S.addr; range->count = S.len; } else range->count = 0; }
static rc_t gather_string_options( Args * args, samdump_opts * opts ) { const char * s; uint32_t count; rc_t rc = get_str_option( args, OPT_PREFIX, &s ); if ( rc == 0 && s != NULL ) { opts->qname_prefix = string_dup_measure( s, NULL ); if ( opts->qname_prefix == NULL ) { rc = RC( rcExe, rcNoTarg, rcValidating, rcMemory, rcExhausted ); (void)LOGERR( klogErr, rc, "error storing QNAME-PREFIX" ); } } if ( rc == 0 ) { rc = get_str_option( args, OPT_Q_QUANT, &s ); if ( rc == 0 && s != NULL ) { opts->qual_quant = string_dup_measure( s, NULL ); if ( opts->qual_quant == NULL ) { rc = RC( rcExe, rcNoTarg, rcValidating, rcMemory, rcExhausted ); (void)LOGERR( klogErr, rc, "error storing QUAL-QUANT" ); } else { bool bres = QualityQuantizerInitMatrix( opts->qual_quant_matrix, opts->qual_quant ); if ( !bres ) { rc = RC( rcExe, rcNoTarg, rcValidating, rcParam, rcInvalid ); (void)LOGERR( klogErr, rc, "error initializing quality-quantizer-matrix" ); } } } } if ( rc == 0 ) { rc = get_str_option( args, OPT_OUTPUTFILE, &s ); if ( rc == 0 && s != NULL ) { opts->outputfile = string_dup_measure( s, NULL ); if ( opts->outputfile == NULL ) { rc = RC( rcExe, rcNoTarg, rcValidating, rcMemory, rcExhausted ); (void)LOGERR( klogErr, rc, "error storing OUTPUTFILE" ); } } } if ( rc == 0 ) { rc = ArgsOptionCount( args, OPT_HDR_COMMENT, &count ); if ( rc == 0 && count > 0 ) { uint32_t i; rc = VNamelistMake( &opts->hdr_comments, 10 ); for ( i = 0; i < count && rc == 0; ++i ) { const char * src; rc = ArgsOptionValue( args, OPT_HDR_COMMENT, i, &src ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "error retrieving comandline option '$(t)' #$(n)", "t=%s,n=%u", OPT_HDR_COMMENT, i ) ); } else { rc = VNamelistAppend( opts->hdr_comments, src ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "error appending hdr-comment '$(t)'", "t=%s", src ) ); } } } if ( rc != 0 ) { VNamelistRelease( opts->hdr_comments ); opts->hdr_comments = NULL; } } } if ( rc == 0 ) { rc = ArgsParamCount( args, &count ); if ( rc == 0 && count > 0 ) { uint32_t i; rc = VNamelistMake( &opts->input_files, 10 ); for ( i = 0; i < count && rc == 0; ++i ) { const char * src; rc = ArgsParamValue( args, i, &src ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "error retrieving comandline param #$(n)", "n=%u", i ) ); } else { rc = VNamelistAppend( opts->input_files, src ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "error appending input_file '$(t)'", "t=%s", src ) ); } } } if ( rc != 0 ) { VNamelistRelease( opts->input_files ); opts->input_files = NULL; } } opts->input_file_count = count; } rc = get_str_option( args, OPT_CIGAR_TEST, &s ); if ( rc == 0 && s != NULL ) { opts->cigar_test = string_dup_measure( s, NULL ); if ( opts->cigar_test == NULL ) { rc = RC( rcExe, rcNoTarg, rcValidating, rcMemory, rcExhausted ); (void)LOGERR( klogErr, rc, "error storing CIGAR-TEST" ); } } return rc; }
/* ListPhysColumns * avail: 2.4 */ LIB_EXPORT rc_t CC VTableListPhysColumns ( const VTable *self, KNamelist **names ) { rc_t rc; if ( names == NULL ) rc = RC ( rcVDB, rcTable, rcListing, rcParam, rcNull ); else { * names = NULL; if ( self == NULL ) rc = RC ( rcVDB, rcTable, rcListing, rcSelf, rcNull ); else { KNamelist *kcol_names; rc = KTableListCol ( self -> ktbl, & kcol_names ); if ( rc == 0 ) { uint32_t kcol_count; rc = KNamelistCount ( kcol_names, & kcol_count ); if ( rc == 0 ) { uint32_t scol_count = 0; KNamelist *scol_names = NULL; const KMDataNode *col_node = self -> col_node; #if LAZY_OPEN_COL_NODE if ( col_node == NULL ) { rc = KMetadataOpenNodeRead ( self -> meta, & ( ( VTable* ) self ) -> col_node, "col" ); if ( rc == 0 || GetRCState ( rc ) != rcNotFound ) col_node = self -> col_node; } #endif if ( col_node != NULL ) { rc = KMDataNodeListChildren ( col_node, & scol_names ); if ( rc == 0 ) rc = KNamelistCount ( scol_names, & scol_count ); } if ( rc == 0 ) { VNamelist *vnames; rc = VNamelistMake ( & vnames, kcol_count + scol_count ); if ( rc == 0 ) { uint32_t i; const char *name; for ( i = 0; i < kcol_count && rc == 0; ++ i ) { rc = KNamelistGet ( kcol_names, i, & name ); if ( rc == 0 ) rc = VNamelistAppend ( vnames, name ); } for ( i = 0; i < scol_count && rc == 0; ++ i ) { rc = KNamelistGet ( scol_names, i, & name ); if ( rc == 0 ) rc = VNamelistAppend ( vnames, name ); } if ( rc == 0 ) { rc = VNamelistToNamelist ( vnames, names ); if ( rc == 0 ) VNamelistReorder ( vnames, false ); } } VNamelistRelease ( vnames ); } KNamelistRelease ( scol_names ); } KNamelistRelease ( kcol_names ); } } } return rc; }