r984: updated to the latest kseq.h
This commit is contained in:
parent
7eabcf42c4
commit
c5fe18438a
18
kseq.h
18
kseq.h
|
|
@ -54,9 +54,9 @@
|
|||
#define __KS_BASIC(type_t, __bufsize) \
|
||||
static inline kstream_t *ks_init(type_t f) \
|
||||
{ \
|
||||
kstream_t *ks = (kstream_t*)calloc(1, sizeof(kstream_t)); \
|
||||
kstream_t *ks = (kstream_t*)calloc(1, sizeof(kstream_t)); \
|
||||
ks->f = f; \
|
||||
ks->buf = (unsigned char*)malloc(__bufsize); \
|
||||
ks->buf = (unsigned char*)malloc(__bufsize); \
|
||||
return ks; \
|
||||
} \
|
||||
static inline void ks_destroy(kstream_t *ks) \
|
||||
|
|
@ -74,8 +74,7 @@
|
|||
if (ks->begin >= ks->end) { \
|
||||
ks->begin = 0; \
|
||||
ks->end = __read(ks->f, ks->buf, __bufsize); \
|
||||
if (ks->end < __bufsize) ks->is_eof = 1; \
|
||||
if (ks->end == 0) return -1; \
|
||||
if (ks->end == 0) { ks->is_eof = 1; return -1;} \
|
||||
} \
|
||||
return (int)ks->buf[ks->begin++]; \
|
||||
}
|
||||
|
|
@ -95,17 +94,16 @@ typedef struct __kstring_t {
|
|||
#define __KS_GETUNTIL(__read, __bufsize) \
|
||||
static int ks_getuntil2(kstream_t *ks, int delimiter, kstring_t *str, int *dret, int append) \
|
||||
{ \
|
||||
int gotany = 0; \
|
||||
if (dret) *dret = 0; \
|
||||
str->l = append? str->l : 0; \
|
||||
if (ks->begin >= ks->end && ks->is_eof) return -1; \
|
||||
for (;;) { \
|
||||
int i; \
|
||||
if (ks->begin >= ks->end) { \
|
||||
if (!ks->is_eof) { \
|
||||
ks->begin = 0; \
|
||||
ks->end = __read(ks->f, ks->buf, __bufsize); \
|
||||
if (ks->end < __bufsize) ks->is_eof = 1; \
|
||||
if (ks->end == 0) break; \
|
||||
if (ks->end == 0) { ks->is_eof = 1; break; } \
|
||||
} else break; \
|
||||
} \
|
||||
if (delimiter == KS_SEP_LINE) { \
|
||||
|
|
@ -124,8 +122,9 @@ typedef struct __kstring_t {
|
|||
if (str->m - str->l < (size_t)(i - ks->begin + 1)) { \
|
||||
str->m = str->l + (i - ks->begin) + 1; \
|
||||
kroundup32(str->m); \
|
||||
str->s = (char*)realloc(str->s, str->m); \
|
||||
str->s = (char*)realloc(str->s, str->m); \
|
||||
} \
|
||||
gotany = 1; \
|
||||
memcpy(str->s + str->l, ks->buf + ks->begin, i - ks->begin); \
|
||||
str->l = str->l + (i - ks->begin); \
|
||||
ks->begin = i + 1; \
|
||||
|
|
@ -134,6 +133,7 @@ typedef struct __kstring_t {
|
|||
break; \
|
||||
} \
|
||||
} \
|
||||
if (!gotany && ks_eof(ks)) return -1; \
|
||||
if (str->s == 0) { \
|
||||
str->m = 1; \
|
||||
str->s = (char*)calloc(1, 1); \
|
||||
|
|
@ -155,7 +155,7 @@ typedef struct __kstring_t {
|
|||
#define __KSEQ_BASIC(SCOPE, type_t) \
|
||||
SCOPE kseq_t *kseq_init(type_t fd) \
|
||||
{ \
|
||||
kseq_t *s = (kseq_t*)calloc(1, sizeof(kseq_t)); \
|
||||
kseq_t *s = (kseq_t*)calloc(1, sizeof(kseq_t)); \
|
||||
s->f = ks_init(fd); \
|
||||
return s; \
|
||||
} \
|
||||
|
|
|
|||
Loading…
Reference in New Issue