X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=blobdiff_plain;f=sam_header.c;h=ddc2c38569f4ee0430439bc10a6e34240939ed5d;hp=d348d10e89b0aa26a1da127b83a1d86091f02763;hb=2fa4cde9b8806faceffb8677440b54ca4c90b6f7;hpb=77734b9975b7f86b4ce3e977729b0329c3414dd7 diff --git a/sam_header.c b/sam_header.c index d348d10..ddc2c38 100644 --- a/sam_header.c +++ b/sam_header.c @@ -366,6 +366,7 @@ static HeaderLine *sam_header_line_parse(const char *headerLine) while (*to && *to=='\t') to++; if ( to-from != 1 ) { debug("[sam_header_line_parse] multiple tabs on line [%s] (%d)\n", headerLine,(int)(to-from)); + free(hline); return 0; } from = to; @@ -669,6 +670,36 @@ char **sam_header2list(const void *_dict, char type[2], char key_tag[2], int *_n return ret; } +void *sam_header2key_val(void *iter, const char type[2], const char key_tag[2], const char value_tag[2], const char **_key, const char **_value) +{ + list_t *l = iter; + if ( !l ) return NULL; + + while (l) + { + HeaderLine *hline = l->data; + if ( hline->type[0]!=type[0] || hline->type[1]!=type[1] ) + { + l = l->next; + continue; + } + + HeaderTag *key, *value; + key = header_line_has_tag(hline,key_tag); + value = header_line_has_tag(hline,value_tag); + if ( !key && !value ) + { + l = l->next; + continue; + } + + *_key = key->value; + *_value = value->value; + return l->next; + } + return l; +} + const char *sam_tbl_get(void *h, const char *key) { khash_t(str) *tbl = (khash_t(str)*)h;