@@ -136,10 +136,10 @@ static void sam_hrecs_remove_ref_altnames(sam_hrecs_t *hrecs, int expected, cons
136
136
* -1 on failure
137
137
*/
138
138
static int sam_hrecs_update_hashes (sam_hrecs_t * hrecs ,
139
- int type ,
139
+ khint32_t type ,
140
140
sam_hrec_type_t * h_type ) {
141
141
/* Add to reference hash? */
142
- if (( type >> 8 ) == 'S' && ( type & 0xff ) == 'Q' ) {
142
+ if (type == TYPEKEY ( "SQ" ) ) {
143
143
sam_hrec_tag_t * tag = h_type -> tag ;
144
144
int nref = hrecs -> nref ;
145
145
const char * name = NULL ;
@@ -259,7 +259,7 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
259
259
}
260
260
261
261
/* Add to read-group hash? */
262
- if (( type >> 8 ) == 'R' && ( type & 0xff ) == 'G' ) {
262
+ if (type == TYPEKEY ( "RG" ) ) {
263
263
sam_hrec_tag_t * tag = sam_hrecs_find_key (h_type , "ID" , NULL );
264
264
int nrg = hrecs -> nrg , r ;
265
265
khint_t k ;
@@ -307,7 +307,7 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
307
307
}
308
308
309
309
/* Add to program hash? */
310
- if (( type >> 8 ) == 'P' && ( type & 0xff ) == 'G' ) {
310
+ if (type == TYPEKEY ( "PG" ) ) {
311
311
sam_hrec_tag_t * tag ;
312
312
sam_hrec_pg_t * new_pg ;
313
313
int npg = hrecs -> npg ;
@@ -392,7 +392,7 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
392
392
return 0 ;
393
393
}
394
394
395
- static int sam_hrecs_remove_hash_entry (sam_hrecs_t * hrecs , int type , sam_hrec_type_t * h_type ) {
395
+ static int sam_hrecs_remove_hash_entry (sam_hrecs_t * hrecs , khint32_t type , sam_hrec_type_t * h_type ) {
396
396
if (!hrecs || !h_type )
397
397
return -1 ;
398
398
@@ -401,7 +401,7 @@ static int sam_hrecs_remove_hash_entry(sam_hrecs_t *hrecs, int type, sam_hrec_ty
401
401
khint_t k ;
402
402
403
403
/* Remove name and any alternative names from reference hash */
404
- if (( type >> 8 ) == 'S' && ( type & 0xff ) == 'Q' ) {
404
+ if (type == TYPEKEY ( "SQ" ) ) {
405
405
const char * altnames = NULL ;
406
406
407
407
tag = h_type -> tag ;
@@ -441,7 +441,7 @@ static int sam_hrecs_remove_hash_entry(sam_hrecs_t *hrecs, int type, sam_hrec_ty
441
441
}
442
442
443
443
/* Remove from read-group hash */
444
- if (( type >> 8 ) == 'R' && ( type & 0xff ) == 'G' ) {
444
+ if (type == TYPEKEY ( "RG" ) ) {
445
445
tag = h_type -> tag ;
446
446
447
447
while (tag ) {
@@ -482,7 +482,7 @@ static int sam_hrecs_remove_hash_entry(sam_hrecs_t *hrecs, int type, sam_hrec_ty
482
482
static void sam_hrecs_global_list_add (sam_hrecs_t * hrecs ,
483
483
sam_hrec_type_t * h_type ,
484
484
sam_hrec_type_t * after ) {
485
- const khint32_t hd_type = 'H' << 8 | 'D' ;
485
+ const khint32_t hd_type = TYPEKEY ( "HD" ) ;
486
486
int update_first_line = 0 ;
487
487
488
488
// First line seen
@@ -536,7 +536,7 @@ static int sam_hrecs_vadd(sam_hrecs_t *hrecs, const char *type, va_list ap, ...)
536
536
sam_hrec_type_t * h_type ;
537
537
sam_hrec_tag_t * h_tag , * last = NULL ;
538
538
int new ;
539
- khint32_t type_i = (type [ 0 ]<< 8 ) | type [ 1 ] , k ;
539
+ khint32_t type_i = TYPEKEY (type ) , k ;
540
540
541
541
if (!strncmp (type , "HD" , 2 ) && (h_type = sam_hrecs_find_type_id (hrecs , "HD" , NULL , NULL )))
542
542
return sam_hrecs_vupdate (hrecs , h_type , ap );
@@ -648,8 +648,7 @@ static int sam_hrecs_vadd(sam_hrecs_t *hrecs, const char *type, va_list ap, ...)
648
648
last = h_tag ;
649
649
}
650
650
651
- int itype = (type [0 ]<<8 ) | type [1 ];
652
- if (-1 == sam_hrecs_update_hashes (hrecs , itype , h_type ))
651
+ if (-1 == sam_hrecs_update_hashes (hrecs , TYPEKEY (type ), h_type ))
653
652
return -1 ;
654
653
655
654
if (!strncmp (type , "PG" , 2 ))
@@ -687,7 +686,7 @@ static int sam_hrecs_remove_line(sam_hrecs_t *hrecs, const char *type_name, sam_
687
686
if (!hrecs || !type_name || !type_found )
688
687
return -1 ;
689
688
690
- int itype = (type_name [ 0 ]<< 8 ) | type_name [ 1 ] ;
689
+ khint32_t itype = TYPEKEY (type_name ) ;
691
690
khint_t k = kh_get (sam_hrecs_t , hrecs -> h , itype );
692
691
if (k == kh_end (hrecs -> h ))
693
692
return -1 ;
@@ -786,12 +785,12 @@ static int sam_hrecs_parse_lines(sam_hrecs_t *hrecs, const char *hdr, size_t len
786
785
return -1 ;
787
786
}
788
787
789
- type = (((uint8_t ) hdr [i + 1 ])<<8 ) | (uint8_t ) hdr [i + 2 ];
790
788
if (!isalpha_c (hdr [i + 1 ]) || !isalpha_c (hdr [i + 2 ])) {
791
789
sam_hrecs_error ("Header line does not have a two character key" ,
792
790
& hdr [l_start ], len - l_start , lno );
793
791
return -1 ;
794
792
}
793
+ type = TYPEKEY (& hdr [i + 1 ]);
795
794
796
795
i += 3 ;
797
796
if (i == len || hdr [i ] == '\n' )
@@ -827,7 +826,7 @@ static int sam_hrecs_parse_lines(sam_hrecs_t *hrecs, const char *hdr, size_t len
827
826
828
827
// Parse the tags on this line
829
828
last = NULL ;
830
- if (( type >> 8 ) == 'C' && ( type & 0xff ) == 'O' ) {
829
+ if (type == TYPEKEY ( "CO" ) ) {
831
830
size_t j ;
832
831
833
832
if (i == len || hdr [i ] != '\t' ) {
@@ -1624,8 +1623,7 @@ int sam_hdr_remove_except(sam_hdr_t *bh, const char *type, const char *ID_key, c
1624
1623
1625
1624
sam_hrec_type_t * type_found = sam_hrecs_find_type_id (hrecs , type , ID_key , ID_value );
1626
1625
if (!type_found ) { // remove all line of this type
1627
- int itype = (type [0 ]<<8 )|(type [1 ]);
1628
- khint_t k = kh_get (sam_hrecs_t , hrecs -> h , itype );
1626
+ khint_t k = kh_get (sam_hrecs_t , hrecs -> h , TYPEKEY (type ));
1629
1627
if (k == kh_end (hrecs -> h ))
1630
1628
return 0 ;
1631
1629
type_found = kh_val (hrecs -> h , k );
@@ -1650,9 +1648,9 @@ int sam_hdr_remove_except(sam_hdr_t *bh, const char *type, const char *ID_key, c
1650
1648
return 0 ;
1651
1649
}
1652
1650
1653
- int sam_hdr_remove_lines (sam_hdr_t * bh , const char * type , const char * id , void * h ) {
1651
+ int sam_hdr_remove_lines (sam_hdr_t * bh , const char * type , const char * id , void * vrh ) {
1654
1652
sam_hrecs_t * hrecs ;
1655
- rmhash_t * rh = (rmhash_t * )h ;
1653
+ rmhash_t * rh = (rmhash_t * )vrh ;
1656
1654
1657
1655
if (!bh || !type )
1658
1656
return -1 ;
@@ -1667,8 +1665,7 @@ int sam_hdr_remove_lines(sam_hdr_t *bh, const char *type, const char *id, void *
1667
1665
hrecs = bh -> hrecs ;
1668
1666
}
1669
1667
1670
- int itype = (type [0 ]<<8 )|(type [1 ]);
1671
- khint_t k = kh_get (sam_hrecs_t , hrecs -> h , itype );
1668
+ khint_t k = kh_get (sam_hrecs_t , hrecs -> h , TYPEKEY (type ));
1672
1669
if (k == kh_end (hrecs -> h )) // nothing to remove from
1673
1670
return 0 ;
1674
1671
@@ -2411,7 +2408,6 @@ sam_hrec_type_t *sam_hrecs_find_type_id(sam_hrecs_t *hrecs, const char *type,
2411
2408
if (!hrecs || !type )
2412
2409
return NULL ;
2413
2410
sam_hrec_type_t * t1 , * t2 ;
2414
- int itype = (type [0 ]<<8 )|(type [1 ]);
2415
2411
khint_t k ;
2416
2412
2417
2413
/* Special case for types we have prebuilt hashes on */
@@ -2444,7 +2440,7 @@ sam_hrec_type_t *sam_hrecs_find_type_id(sam_hrecs_t *hrecs, const char *type,
2444
2440
}
2445
2441
}
2446
2442
2447
- k = kh_get (sam_hrecs_t , hrecs -> h , itype );
2443
+ k = kh_get (sam_hrecs_t , hrecs -> h , TYPEKEY ( type ) );
2448
2444
if (k == kh_end (hrecs -> h ))
2449
2445
return NULL ;
2450
2446
0 commit comments