X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kstring.c;h=b8ff45c758128c6760c494b8c97d7e06d2a676bd;hb=9f118264ea012adc21a46d7c03eaad4f9ce7d4d4;hp=a09180bde9fe38fe7f7fe255de1708f22c3945b7;hpb=94027d8bf194b5e62b98d8a2b240a3ab1c439b46;p=samtools.git diff --git a/kstring.c b/kstring.c index a09180b..b8ff45c 100644 --- a/kstring.c +++ b/kstring.c @@ -29,16 +29,24 @@ char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux) const char *p, *start; if (sep) { // set up the table if (str == 0 && (aux->tab[0]&1)) return 0; // no need to set up if we have finished - aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0; - for (p = sep; *p; ++p) - aux->tab[*p/64] |= 1ull<<(*p%64); + aux->finished = 0; + if (sep[1]) { + aux->sep = -1; + aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0; + for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f); + } else aux->sep = sep[0]; + } + if (aux->finished) return 0; + else if (str) aux->p = str - 1, aux->finished = 0; + if (aux->sep < 0) { + for (p = start = aux->p + 1; *p; ++p) + if (aux->tab[*p>>6]>>(*p&0x3f)&1) break; + } else { + for (p = start = aux->p + 1; *p; ++p) + if (*p == aux->sep) break; } - if (str) aux->p = str - 1, aux->tab[0] &= ~1ull; - else if (aux->tab[0]&1) return 0; - for (p = start = aux->p + 1; *p; ++p) - if (aux->tab[*p/64]>>(*p%64)) break; aux->p = p; // end of token - if (*p == 0) aux->tab[0] |= 1; // no more tokens + if (*p == 0) aux->finished = 1; // no more tokens return (char*)start; } @@ -90,13 +98,13 @@ typedef unsigned char ubyte_t; static int *ksBM_prep(const ubyte_t *pat, int m) { int i, *suff, *prep, *bmGs, *bmBc; - prep = calloc(m + 256, sizeof(int)); + prep = (int*)calloc(m + 256, sizeof(int)); bmGs = prep; bmBc = prep + m; { // preBmBc() for (i = 0; i < 256; ++i) bmBc[i] = m; for (i = 0; i < m - 1; ++i) bmBc[pat[i]] = m - i - 1; } - suff = calloc(m, sizeof(int)); + suff = (int*)calloc(m, sizeof(int)); { // suffixes() int f = 0, g; suff[m - 1] = m;