63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
# include <zlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
|
|
bool StartsWith(const char *a, const char *b)
|
|
{
|
|
if(strncmp(a, b, strlen(b)) == 0) return 1;
|
|
return 0;
|
|
}
|
|
|
|
void slice_str(const char * str, char * buffer, size_t start, size_t end)
|
|
{
|
|
size_t j = 0;
|
|
for ( size_t i = start; i <= end; ++i ) {
|
|
buffer[j++] = str[i];
|
|
}
|
|
buffer[j] = 0;
|
|
}
|
|
|
|
|
|
# define LL 8192 /* line length maximum */
|
|
|
|
int main ( int argc, char *argv[] ){
|
|
if ( argc < 3) {
|
|
printf("Need 2 args!\n");
|
|
return 1;
|
|
}
|
|
gzFile fp;
|
|
char line[LL];
|
|
char delim[] = "\t";
|
|
fp = gzopen( argv[1], "r" );
|
|
|
|
gzgets( fp, line, LL );
|
|
while ( ! gzeof( fp ) ){
|
|
int k = 0;
|
|
if ( StartsWith(line, "##") || ( StartsWith(line, "#") ) || (strstr(line, "./.:.") != NULL)){
|
|
gzgets( fp, line, LL );
|
|
continue;
|
|
}
|
|
|
|
char *vcf_field = strtok(line, delim);
|
|
while(vcf_field != NULL){
|
|
k++;
|
|
if (k > 9) {
|
|
const size_t len = strlen(vcf_field);
|
|
char buffer[len + 1];
|
|
//printf("'%s'\n", ptr);
|
|
slice_str(vcf_field, buffer, 0, 0);
|
|
printf("%s ", buffer);
|
|
}
|
|
vcf_field = strtok(NULL, delim);
|
|
}
|
|
// printf("%s", line );
|
|
// loads the next line
|
|
gzgets( fp, line, LL );
|
|
}
|
|
|
|
gzclose( fp );
|
|
return 0;
|
|
}
|