aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-03-24 15:25:15 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2014-03-24 15:25:15 -0400
commit375ab82530af1f6dbf26db6222680d483014a0e3 (patch)
tree17ae6fe13faf0da400f337fdc85b1dfede5684b5 /src
parent9afddef02b7e423128bb8db686d888dd6184bd2d (diff)
fix strstream to work with mers list
Diffstat (limited to 'src')
-rw-r--r--src/strstream.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/strstream.c b/src/strstream.c
index c4c30fa..d1ceb65 100644
--- a/src/strstream.c
+++ b/src/strstream.c
@@ -59,16 +59,11 @@ int main(int argc, char **argv){
int i = 0;
- if(argc != 3) {
+ if(argc != 2) {
fprintf(stderr, "usage: strstream merlist.txt\n");
exit(EXIT_FAILURE);
}
- //
- FILE *infh = fopen(argv[2], "r");
- if(infh == NULL) {
- fprintf(stderr, "could not open %s\n", argv[2]);
- exit(EXIT_FAILURE);
- }
+
// load mers
FILE *fh = fopen(argv[1], "r");
if(fh == NULL) {
@@ -94,8 +89,13 @@ int main(int argc, char **argv){
buf = buffer;
start = buf + cpy;
- // read into "start" (buf + cpy) from stdin
- while((len = fread(start, 1, cpy_size, infh)) != 0) {
+ // copy our first cpy length into the first part of our buffer
+ len = fread(buffer, 1, cpy, stdin);
+ if(len == 0)
+ exit(EXIT_FAILURE);
+
+ // read into "start" (buf + cpy) from tdin
+ while((len = fread(start, 1, cpy_size, stdin)) != 0) {
for(i = 0; i < mer_len; i++) {
char *p = buffer;
while((p = strstr(p, mers[i])) != NULL) {
@@ -106,5 +106,6 @@ int main(int argc, char **argv){
memcpy(buffer, buffer + len, cpy);
pos = pos + len;
}
+
return 0;
}