|
4 | 4 | #include <errno.h> |
5 | 5 | #include <string.h> |
6 | 6 |
|
7 | | -#define BUF_SIZE 4096 |
| 7 | +#define BUF_SIZE 8192 |
8 | 8 |
|
9 | 9 | char *dict = NULL; |
10 | 10 | char **dict_name; |
@@ -161,26 +161,34 @@ int main (int argc, char* argv[]){ |
161 | 161 |
|
162 | 162 | read_dict_file(dict); |
163 | 163 |
|
164 | | - char *line = malloc(BUF_SIZE * sizeof(char)); |
165 | | - while(gets(line)){ |
| 164 | + //Read from stdin and write to stdout |
| 165 | + char *line = NULL; |
| 166 | + ssize_t read; |
| 167 | + size_t linelen = 0; |
| 168 | + |
| 169 | + while((read = getline(&line,&linelen,stdin)) != -1){ |
166 | 170 | if(strncmp(line, "@", 1) == 0){//If we're matching a header |
167 | 171 | if(strncmp(line, "@SQ" ,3)==0){//Code to replace/append to SQ lines here @SQ |
168 | 172 | char *nom = get_contig_name_fromSQ_line(line); |
169 | 173 | char *new = get_dict_sq_line_by_name(nom); |
170 | 174 | fprintf(stdout,"%s",new); |
| 175 | + fflush(stdout); |
171 | 176 | free(nom); |
172 | 177 | }else{//Not a SQ header |
173 | | - puts(line); |
| 178 | + fprintf(stdout,"%s",line); |
174 | 179 | } |
175 | 180 | }else{ // We're no longer matching a header |
176 | | - puts(line); |
| 181 | + fprintf(stdout,"%s",line); |
177 | 182 | break; |
178 | 183 | }//End of checking for a header |
179 | 184 | } |
180 | | - while(gets(line)){ |
181 | | - puts(line); |
| 185 | + //Another loop, this time we know we're past the SQ headers so it goes straight to stdout. |
| 186 | + while((read = getline(&line,&linelen,stdin)) != -1){ |
| 187 | + fprintf(stdout,"%s",line); |
182 | 188 | } |
| 189 | + fflush(stdout); |
183 | 190 | free(line); |
| 191 | + |
184 | 192 | int j=0; |
185 | 193 | for(j=0;j<dict_entries;j++){ |
186 | 194 | free(dict_name[j]); |
|
0 commit comments