-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpatch.c
executable file
·40 lines (28 loc) · 882 Bytes
/
patch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "utils.h"
int patch_main(int argc, char *argv[]){
if ( optind == argc || argc != optind + 2) {
fprintf(stderr, "\nUsage: atlas-utils patch <tsv> <label:p>\n\n");
return 1;
}
kstring_t kt = {0, 0, 0};
gzFile fp;
fp = strcmp(argv[ optind ], "-")? gzopen(argv[ optind ], "r") : gzdopen(fileno(stdin), "r");
if (fp) {
kstream_t *ks;
ks = ks_init(fp);
while(ks_getuntil(ks, '\n', &kt, 0) >= 0){
if(kt.s[0] == '#'){
printf("%s\n", kt.s);
continue;
}
printf("%s:%s\n", argv[optind + 1], kt.s);
}
ks_destroy(ks);
gzclose(fp);
}else{
fprintf(stderr, "[ERR]: can't open file %s\n", argv[ optind ]);
exit(1);
}
free(kt.s);
return 0;
}