X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=inline;f=kseq.h;h=82face095919a3991b1f927bb5422ffd95f102a4;hb=c9a9c2742eecde8e097f70efdb6d599374ca325e;hp=25f31a3c7f12addf8f1ae9e6da508f4d384b8f05;hpb=f93dae0d03856955f9424e8b2aaf261304ca647e;p=samtools.git diff --git a/kseq.h b/kseq.h index 25f31a3..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) \ @@ -71,10 +81,13 @@ return (int)ks->buf[ks->begin++]; \ } +#ifndef KSTRING_T +#define KSTRING_T kstring_t typedef struct __kstring_t { size_t l, m; char *s; } kstring_t; +#endif #ifndef kroundup32 #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) @@ -96,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); \ @@ -116,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; \ }