annotate bwa-0.6.2/kstring.h @ 0:dd1186b11b3b draft

Uploaded BWA
author ashvark
date Fri, 18 Jul 2014 07:55:14 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
1 #ifndef KSTRING_H
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
2 #define KSTRING_H
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
3
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
4 #include <stdlib.h>
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
5 #include <string.h>
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
6
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
7 #ifndef kroundup32
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
8 #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
9 #endif
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
10
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
11 #ifndef KSTRING_T
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
12 #define KSTRING_T kstring_t
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
13 typedef struct __kstring_t {
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
14 size_t l, m;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
15 char *s;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
16 } kstring_t;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
17 #endif
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
18
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
19 static inline int kputs(const char *p, kstring_t *s)
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
20 {
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
21 int l = strlen(p);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
22 if (s->l + l + 1 >= s->m) {
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
23 s->m = s->l + l + 2;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
24 kroundup32(s->m);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
25 s->s = (char*)realloc(s->s, s->m);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
26 }
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
27 strcpy(s->s + s->l, p);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
28 s->l += l;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
29 return l;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
30 }
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
31
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
32 static inline int kputc(int c, kstring_t *s)
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
33 {
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
34 if (s->l + 1 >= s->m) {
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
35 s->m = s->l + 2;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
36 kroundup32(s->m);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
37 s->s = (char*)realloc(s->s, s->m);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
38 }
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
39 s->s[s->l++] = c;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
40 s->s[s->l] = 0;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
41 return c;
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
42 }
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
43
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
44 int ksprintf(kstring_t *s, const char *fmt, ...);
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
45
dd1186b11b3b Uploaded BWA
ashvark
parents:
diff changeset
46 #endif