X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kseq.h;h=82face095919a3991b1f927bb5422ffd95f102a4;hb=d195bcfb6632c68032a89c091c20dc24dd6ded60;hp=2875c77577152eb9a20b41fc044288f67eb124ab;hpb=42e756837f7acb91bfd1134ef16d423e71c913d7;p=samtools.git diff --git a/kseq.h b/kseq.h index 2875c77..82face0 100644 --- a/kseq.h +++ b/kseq.h @@ -25,6 +25,12 @@ /* Contact: Heng Li */ +/* + 2009-07-16 (lh3): in kstream_t, change "char*" to "unsigned char*" + */ + +/* Last Modified: 12APR2009 */ + #ifndef AC_KSEQ_H #define AC_KSEQ_H @@ -32,9 +38,13 @@ #include #include +#define KS_SEP_SPACE 0 // isspace(): \t, \n, \v, \f, \r +#define KS_SEP_TAB 1 // isspace() && !' ' +#define KS_SEP_MAX 1 + #define __KS_TYPE(type_t) \ typedef struct __kstream_t { \ - char *buf; \ + unsigned char *buf; \ int begin, end, is_eof; \ type_t f; \ } kstream_t; @@ -47,7 +57,7 @@ { \ kstream_t *ks = (kstream_t*)calloc(1, sizeof(kstream_t)); \ ks->f = f; \ - ks->buf = (char*)malloc(__bufsize); \ + ks->buf = malloc(__bufsize); \ return ks; \ } \ static inline void ks_destroy(kstream_t *ks) \ @@ -99,13 +109,16 @@ typedef struct __kstring_t { if (ks->end == 0) break; \ } else break; \ } \ - if (delimiter) { \ + if (delimiter > KS_SEP_MAX) { \ for (i = ks->begin; i < ks->end; ++i) \ if (ks->buf[i] == delimiter) break; \ - } else { \ + } else if (delimiter == KS_SEP_SPACE) { \ for (i = ks->begin; i < ks->end; ++i) \ if (isspace(ks->buf[i])) break; \ - } \ + } else if (delimiter == KS_SEP_TAB) { \ + for (i = ks->begin; i < ks->end; ++i) \ + if (isspace(ks->buf[i]) && ks->buf[i] != ' ') break; \ + } else i = 0; /* never come to here! */ \ if (str->m - str->l < i - ks->begin + 1) { \ str->m = str->l + (i - ks->begin) + 1; \ kroundup32(str->m); \ @@ -119,6 +132,10 @@ typedef struct __kstring_t { break; \ } \ } \ + if (str->l == 0) { \ + str->m = 1; \ + str->s = (char*)calloc(1, 1); \ + } \ str->s[str->l] = '\0'; \ return str->l; \ }