Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 57 lines (48 sloc) 1.995 kb
f5acd5b converted fastacomplement to pipeline model
greg authored
1 /*
2 * Implement 'seekable' sequence data on top of stream-oriented lower layer -
3 * allow client programs to look at any part of the sequence, not just
4 * in its natural order
5e034f6 Added GPLv3 license
greg authored
5 *
6 * Copyright (C) 2011, Greg Benison
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
f5acd5b converted fastacomplement to pipeline model
greg authored
22 */
23
24 #include <stdlib.h>
25
26 static char *sequence;
27 static char *sequence_ptr;
28 int sequence_max_length;
29
30 static char *comment;
31 static char *comment_ptr;
32 int comment_max_length;
33
34 #define INIT_ARRAY(name, init_length) {\
35 name##_max_length = init_length; \
36 name = (char*)malloc(name##_max_length); \
37 name##_ptr = name; \
38 }
39
40 #define PUSH_ARRAY(name, c) {\
41 if ((name##_ptr - name) >= (name##_max_length - 1)) \
dc6e3a1 bugfix: realloc moves the pointer
greg authored
42 {name##_max_length *= 2; \
43 int len = name##_ptr - name; \
44 name = realloc(name, name##_max_length); name##_ptr = name + len;} \
f5acd5b converted fastacomplement to pipeline model
greg authored
45 *name##_ptr = c; ++name##_ptr; }
46
47 extern void process_sequence(char*, char*);
48
49 void init_sequence() { INIT_ARRAY(sequence, 128); }
50 void handle_sequence(char c) { PUSH_ARRAY(sequence, c); }
51 void terminate_sequence() { *sequence_ptr = 0;
52 process_sequence(comment, sequence); }
53
54 void init_comment() { INIT_ARRAY(comment, 32); }
55 void handle_comment(char c) { PUSH_ARRAY(comment, c); }
56 void terminate_comment() { *comment_ptr = 0; }
Something went wrong with that request. Please try again.