示例#1
0
static int
moderator_discard_message (mu_sieve_machine_t mach, mu_message_t request,
			   const char *from)
{
  int rc;
  mu_message_t reply;
  mu_header_t repl_hdr, req_hdr;
  mu_mailer_t mailer;
  
  rc = mu_message_create (&reply, NULL);
  if (rc)
    return rc;
  rc = mu_message_get_header (reply, &repl_hdr);
  if (rc)
    {
      mu_message_destroy (&reply, NULL);
      return rc;
    }
  
  rc = mu_message_get_header (request, &req_hdr);
  if (rc)
    {
      mu_message_destroy (&reply, NULL);
      return rc;
    }

  if (copy_header (mach, repl_hdr, MU_HEADER_TO, req_hdr, MU_HEADER_FROM)
      || copy_header (mach,
		      repl_hdr, MU_HEADER_SUBJECT, req_hdr, MU_HEADER_SUBJECT))
    {
      mu_message_destroy (&reply, NULL);
      return rc;
    }

  if (from)
    mu_header_set_value (repl_hdr, MU_HEADER_FROM, from, 0);

  mailer = mu_sieve_get_mailer (mach);
  rc = mu_mailer_open (mailer, 0);
  if (rc)
    mu_sieve_error (mach, _("cannot open mailer: %s"),
		    mu_strerror (rc));
  else
    {
      rc = mu_mailer_send_message (mailer, reply, NULL, NULL);
      mu_mailer_close (mailer);

      if (rc)
	mu_sieve_error (mach, _("cannot send message: %s"),
			mu_strerror (rc));
    }
  mu_message_destroy (&reply, NULL);
  return rc;
}
示例#2
0
void set_up_snd_io(chan_info *cp, int i, int fd, const char *filename, file_info *hdr, bool post_close)
{
  snd_io *io;
  snd_file_open_descriptors(fd,
			    filename,
			    hdr->format,
			    hdr->data_location,
			    hdr->chans,
			    hdr->type);
  io = make_file_state(fd, hdr, i, 0,
		       (post_close) ? MAX_BUFFER_SIZE : MIX_FILE_BUFFER_SIZE);
  cp->sounds[0] = make_snd_data_file(filename, io,
				     copy_header(hdr->name, hdr),
				     DONT_DELETE_ME, cp->edit_ctr, i);
  if (post_close) 
    {
      snd_data *sd;
      sd = cp->sounds[0]; 
      sd->open = FD_CLOSED; 
      io->fd = -1;
      if (mus_file_close(fd) != 0)
	snd_error("can't close file %s: %s", filename, snd_io_strerror());
    }
  /* this is not as crazy as it looks -- we've read in the first 64K (or whatever) samples,
   * and may need this file channel for other opens, so this file can be closed until reposition_file_state_buffers
   */
}
示例#3
0
static void add_child4(art_node4 *n, art_node **ref, unsigned char c, void *child) {
    if (n->n.num_children < 4) {
        int idx;
        for (idx=0; idx < n->n.num_children; idx++) {
            if (c < n->keys[idx]) break;
        }

        // Shift to make room
        memmove(n->keys+idx+1, n->keys+idx, n->n.num_children - idx);
        memmove(n->children+idx+1, n->children+idx,
                (n->n.num_children - idx)*sizeof(void*));

        // Insert element
        n->keys[idx] = c;
        n->children[idx] = (art_node*)child;
        n->n.num_children++;

    } else {
        art_node16 *new_node = (art_node16*)alloc_node(NODE16);

        // Copy the child pointers and the key map
        memcpy(new_node->children, n->children,
                sizeof(void*)*n->n.num_children);
        memcpy(new_node->keys, n->keys,
                sizeof(unsigned char)*n->n.num_children);
        copy_header((art_node*)new_node, (art_node*)n);
        *ref = (art_node*)new_node;
        free(n);
        add_child16(new_node, ref, c, child);
    }
}
示例#4
0
static void remove_child16(art_node16 *n, art_node **ref, art_node **l) {
    int pos = l - n->children;
    memmove(n->keys+pos, n->keys+pos+1, n->n.num_children - 1 - pos);
    memmove(n->children+pos, n->children+pos+1, (n->n.num_children - 1 - pos)*sizeof(void*));
    n->n.num_children--;

    if (n->n.num_children == 3) {
        art_node4 *new_node = (art_node4*)alloc_node(NODE4);
        *ref = (art_node*)new_node;
        copy_header((art_node*)new_node, (art_node*)n);
        memcpy(new_node->keys, n->keys, 4);
        memcpy(new_node->children, n->children, 4*sizeof(void*));
        free(n);
    }
}
示例#5
0
static void add_child16(art_node16 *n, art_node **ref, unsigned char c, void *child) {
    if (n->n.num_children < 16) {
        __m128i cmp;

        // Compare the key to all 16 stored keys
        cmp = _mm_cmplt_epi8(_mm_set1_epi8(c),
                _mm_loadu_si128((__m128i*)n->keys));

        // Use a mask to ignore children that don't exist
        unsigned mask = (1 << n->n.num_children) - 1;
        unsigned bitfield = _mm_movemask_epi8(cmp) & mask;

        // Check if less than any
        unsigned idx;
        if (bitfield) {
            idx = __builtin_ctz(bitfield);
            memmove(n->keys+idx+1,n->keys+idx,n->n.num_children-idx);
            memmove(n->children+idx+1,n->children+idx,
                    (n->n.num_children-idx)*sizeof(void*));
        } else
            idx = n->n.num_children;

        // Set the child
        n->keys[idx] = c;
        n->children[idx] = (art_node*)child;
        n->n.num_children++;

    } else {
        art_node48 *new_node = (art_node48*)alloc_node(NODE48);

        // Copy the child pointers and populate the key map
        memcpy(new_node->children, n->children,
                sizeof(void*)*n->n.num_children);
        for (int i=0;i<n->n.num_children;i++) {
            new_node->keys[n->keys[i]] = i + 1;
        }
        copy_header((art_node*)new_node, (art_node*)n);
        *ref = (art_node*)new_node;
        free(n);
        add_child48(new_node, ref, c, child);
    }
}
示例#6
0
static void add_child48(art_node48 *n, art_node **ref, unsigned char c, void *child) {
    if (n->n.num_children < 48) {
        int pos = 0;
        while (n->children[pos]) pos++;
        n->children[pos] = (art_node*)child;
        n->keys[c] = pos + 1;
        n->n.num_children++;
    } else {
        art_node256 *new_node = (art_node256*)alloc_node(NODE256);
        for (int i=0;i<256;i++) {
            if (n->keys[i]) {
                new_node->children[i] = n->children[n->keys[i] - 1];
            }
        }
        copy_header((art_node*)new_node, (art_node*)n);
        *ref = (art_node*)new_node;
        free(n);
        add_child256(new_node, ref, c, child);
    }
}
示例#7
0
static void remove_child256(art_node256 *n, art_node **ref, unsigned char c) {
    n->children[c] = NULL;
    n->n.num_children--;

    // Resize to a node48 on underflow, not immediately to prevent
    // trashing if we sit on the 48/49 boundary
    if (n->n.num_children == 37) {
        art_node48 *new_node = (art_node48*)alloc_node(NODE48);
        *ref = (art_node*)new_node;
        copy_header((art_node*)new_node, (art_node*)n);

        int pos = 0;
        for (int i=0;i<256;i++) {
            if (n->children[i]) {
                new_node->children[pos] = n->children[i];
                new_node->keys[i] = pos + 1;
                pos++;
            }
        }
        free(n);
    }
}
示例#8
0
static void remove_child48(art_node48 *n, art_node **ref, unsigned char c) {
    int pos = n->keys[c];
    n->keys[c] = 0;
    n->children[pos-1] = NULL;
    n->n.num_children--;

    if (n->n.num_children == 12) {
        art_node16 *new_node = (art_node16*)alloc_node(NODE16);
        *ref = (art_node*)new_node;
        copy_header((art_node*)new_node, (art_node*)n);

        int child = 0;
        for (int i=0;i<256;i++) {
            pos = n->keys[i];
            if (pos) {
                new_node->keys[child] = i;
                new_node->children[child] = n->children[pos - 1];
                child++;
            }
        }
        free(n);
    }
}
示例#9
0
//for NVIEWSHEDS small, the resulting map is basically all empty;
//the interpolate function extends each non-empty output viewshed
//value to a ball centered at that point
void interpolate_raster(Grid* outgrid, char* output_name) {
  
  assert(outgrid);
  printf("\n-----\n");
  printf("Multiviewshed done, interpolating result grid."); 
  printf("total  %d viewsheds: ", nvp); 

  /*create the interpolated output raster */
  Grid* intgrid = create_empty_grid(); 
  assert(intgrid); 
  copy_header(intgrid->hd, outgrid->hd); 
  alloc_grid_data(intgrid); 

  int nrows, ncols, row, col;
  nrows = intgrid->hd->nrows; 
  ncols = intgrid->hd->ncols; 
  
  int nvis; 
  for(row = 0; row < nrows; row++) {
    for(col = 0; col < ncols; col++) {  
      
      nvis = findClosestViewpoint(row,col);
      //printf("%d %d :%d\n", row, col, nvis); 
      set(intgrid, row, col,  nvis); 
    }//for col
  } //for row 
  
  /* write grid to file */
  char* interp_name = (char*)malloc((strlen(output_name+8))*sizeof(char)); 
  assert(interp_name); 
  strcpy(interp_name,output_name);
  strcat(interp_name, "-interp"); 
  printf("creating interpolated raster: %s\n", interp_name); 
  save_grid_to_arcascii_file(intgrid, interp_name); 

  destroy_grid(intgrid);
}
示例#10
0
int
main (int argc, char **argv)
{
unsigned int   i, j, k;
unsigned int unsupported = 0;
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbTableDef *table;
MdbColumn *col;
FILE *typesfile;
FILE *headerfile;
FILE *cfile;

 if (argc < 2) {
   fprintf (stderr, "Usage: %s <file>\n",argv[0]);
   exit (1);
 }

 mdb_init();

 /* open the database */

 mdb = mdb_open (argv[1], MDB_NOFLAGS);
 if (!mdb) {
 	mdb_exit();
	exit(1);
 }

 typesfile = fopen ("types.h", "w");
 headerfile = fopen ("dumptypes.h", "w");
 cfile = fopen ("dumptypes.c", "w");

 copy_header (typesfile);
 copy_header (headerfile);
 fprintf (headerfile, "#include \"types.h\"\n");
 copy_header (cfile);
 fprintf (cfile, "#include <stdio.h>\n");
 fprintf (cfile, "#include \"dumptypes.h\"\n");
 
 /* read the catalog */
 
 mdb_read_catalog (mdb, MDB_TABLE);

 /* loop over each entry in the catalog */

 for (i=0; i < mdb->num_catalog; i++) 
   {
     entry = g_ptr_array_index (mdb->catalog, i);

     if (!mdb_is_user_table(entry))
          continue;

	       fprintf (typesfile, "typedef struct _%s\n", entry->object_name);
	       fprintf (typesfile, "{\n");

	       fprintf (headerfile, "void dump_%s (%s x);\n",
			entry->object_name, entry->object_name);
	       fprintf (cfile, "void dump_%s (%s x)\n{\n",
			entry->object_name, entry->object_name);
	       fprintf (cfile, "\tfprintf (stdout, \"**************** %s ****************\\n\");\n", entry->object_name);
	       table = mdb_read_table (entry);

	       /* get the columns */
	       mdb_read_columns (table);

	       /* loop over the columns, dumping the names and types */

	       for (k = 0; k < table->num_cols; k++)
		 {
		   col = g_ptr_array_index (table->columns, k);
		   fprintf (cfile, "\tfprintf (stdout, \"x.");
		   for (j = 0; j < strlen (col->name); j++)
		     {
		       fprintf (cfile, "%c", tolower (col->name [j]));
		     }
		   fprintf (cfile, " = \");\n");
		   switch (col->col_type)
		     {
		     case MDB_INT:
		       fprintf (typesfile, "\tint\t");
		       fprintf (cfile, "\tdump_int (x.");
		       break;
		     case MDB_LONGINT:
		       fprintf (typesfile, "\tlong\t");
		       fprintf (cfile, "\tdump_long (x.");
		       break;
		     case MDB_TEXT:
		     case MDB_MEMO:
		       fprintf (typesfile, "\tchar *\t");
		       fprintf (cfile, "\tdump_string (x.");
		       break;
		     default:
		       unsupported = 1;
		       break;
		     }
		   for (j = 0; j < strlen (col->name); j++)
		     {
		       fprintf (typesfile, "%c", tolower (col->name [j]));
		       fprintf (cfile, "%c", tolower (col->name [j]));
		     }
		   fprintf (typesfile, ";\n");
		   fprintf (cfile, ");\n");
		 }

	       fprintf (typesfile, "\n} %s ;\n", entry->object_name);
	       fprintf (typesfile, "\n");
	       fprintf (cfile, "}\n\n");

	       mdb_free_tabledef(table);
   }

 fclose (headerfile);
 fclose (typesfile);
 fclose (cfile);
 
 mdb_close (mdb);
 mdb_exit();

 if (unsupported)
  fputs("ERROR: unsupported type.\n", stderr);
 exit(unsupported);
}
示例#11
0
main (int argc, char **argv)
{
  char txt_filename [FILENAMESIZE];
  char c_filename [FILENAMESIZE];
  FILE *txtfile;
  FILE *cfile;
  int count;
  char input [BUFFERSIZE];
  int location;
  char c;
  int instring;
  int lastcomma;
  int i;

  if (argc < 2)
    {
      fprintf (stderr, "Usage: %s <file> (assumed extension .txt)\n",argv[0]);
      exit (1);
    }

  strcpy (txt_filename, argv [1]);
  txtfile = fopen (txt_filename, "r");
  if (!txtfile) {
  	strcat (txt_filename, ".txt");
  	txtfile = fopen (txt_filename, "r");
  	if (!txtfile) exit(1);
  } else {
	/* strip away extension */
	for (i=strlen(txt_filename);i > 0 && txt_filename[i]!='.';i--);
	if (txt_filename[i]=='.') txt_filename[i]='\0';
  }

  strcpy (c_filename, argv [1]);
  strcat (c_filename, ".c");

  cfile = fopen (c_filename, "w");

  copy_header (cfile);
  fprintf (cfile, "\n");
  fprintf (cfile, "#include <stdio.h>\n");
  fprintf (cfile, "#include \"types.h\"\n");
  fprintf (cfile, "#include \"mdbsupport.h\"\n");
  fprintf (cfile, "\n");

  fprintf (cfile, "const %s %s_array [] = {\n", argv [1], argv [1]);

  c = 0;
  count = 0;
  while (c != -1)
    {
      location = 0;
      memset (input, 0, BUFFERSIZE);
      while ((c = fgetc (txtfile)) != NL)
	{
	  if (c == -1)
	    break;
	  input [location++] = c;
	}	
      input [location] = '\0';
      if (location > 0)
	{
	  if (count != 0)
	    {
	      fprintf (cfile, ",\n");
	    }
	  fprintf (cfile, "{\t\t\t\t/* %6d */\n\t", count);
	  instring = FALSE;
	  lastcomma = FALSE;
	  for (i = 0; i < location; i++)
	    {
	      if (instring)
		{
		  if (input [i] == '\\')
		    fprintf (cfile, "\\\\");
		  else if (input [i] == LF)
		    fprintf (cfile, "\\n");
		  else if (input [i] != NL)
		    fprintf (cfile, "%c", input [i]);
		  if (input [i] == '"')
		    {
		      instring = FALSE;
		      lastcomma = FALSE;
		    }
		}
	      else
		{
		  switch (input [i])
		    {
		    case ',':
		      if (lastcomma)
			fprintf (cfile, "\"\"");
		      fprintf (cfile, ",\n\t");
		      lastcomma = TRUE;
		      break;
		    case '"':
		      fprintf (cfile, "%c", input [i]);
		      lastcomma = FALSE;
		      instring = TRUE;
		      break;
		    default:
		      fprintf (cfile, "%c", input [i]);
		      lastcomma = FALSE;
		      break;
		    }
		}
	    }
	  if (lastcomma)
	    fprintf (cfile, "\"\"\n");
	  fprintf (cfile, "\n}");
	  count++;
	}
      c = fgetc (txtfile);
    }

  fprintf (cfile, "\n};\n");
  fprintf (cfile, "\nconst int %s_array_length = %d;\n", argv [1], count);

  fclose (txtfile);
  fclose (cfile);

  fprintf (stdout, "count = %d\n", count);


  exit(0);
}
示例#12
0
int main(int argc, char* argv[]) {

 //this variable collects all user options
  MultiviewOptions options;

  parse_args(argc, argv, &options); 
  record_args(options);

#ifdef INTERPOLATE_RESULT 
  viewsheds = (Nvis*) malloc((options->NVIEWSHEDS+10)*sizeof(Nvis)); 
  assert(viewsheds);
#endif 


  //read input raster 
  printf("reading input grid %s ", options.input_name); 
  Grid *ingrid = read_grid_from_arcascii_file(options.input_name);
  assert(ingrid); 
  printf("..done\n");

  //number of rows and columns in the grid 
  int nrows, ncols;  
  nrows = ingrid->hd->nrows; 
  ncols = ingrid->hd->ncols; 
  printf("grid: rows = %d, cols = %d\n", nrows, ncols);

  if (options.NVIEWSHEDS ==0) 
    options.NVIEWSHEDS = nrows * ncols; 

  //create an output grid 
  Grid* outgrid = create_empty_grid(); 
  assert(outgrid);
  //outgrid->hd = create_empty_header(); 
  //the header is allocated in create_empty_grid()
  copy_header(outgrid->hd, *(ingrid->hd)); 
  alloc_grid_data(outgrid); 


  /* **************************************** */
  /* INITIALIZE EVENT LIST */
  /* **************************************** */

  /*allocate the eventlist to hold the maximum number of events possible*/
  Event* eventList;
  eventList = (Event*) malloc(ncols * nrows * 3 * sizeof(Event));
  assert(eventList);
  
  /*initialize the eventList with the info common to all viewpoints */
  long  nevents;
  Rtimer initTime; 
  rt_start(initTime);
  nevents  = init_event_list(eventList, ingrid );
  printf("nb events = %ld\n", nevents);
  rt_stop(initTime); 
  print_init_timings(initTime); 
  
 

  /* ****************************** */   
  /* compute the viewshed of the i % DO_EVERY point  */
  /* ****************************** */   
  
  assert(options.NVIEWSHEDS > 0);
  int DO_EVERY = nrows * ncols/ options.NVIEWSHEDS; 
  /* start going through the data and considering each point, in turn,
     as a viewshed */
 
  if (options.SWEEP_MODE == SWEEP_DISTRIBUTE)  {
    assert(options.BASECASE_THRESHOLD >0 && options.NUM_SECTORS >0);
    compute_multiviewshed_distribution(options, DO_EVERY,
				       ingrid, outgrid,  nevents, eventList); 
  }
  else { 
    compute_multiviewshed_radial(options, DO_EVERY, ingrid, outgrid, 
				 nevents, eventList);
  }


  /* ****************************** */
  /*all sweeping and computing done - clean up */
  free(eventList);

  //write output grid to file 
  save_grid_to_arcascii_file(outgrid, options.output_name); 

  //clean up 
  destroy_grid(ingrid); 
  destroy_grid(outgrid); 


#ifdef INTERPOLATE_RESULT
  //for NVIEWSHEDS small, the resulting map is basically all empty;
  //the interpolate function extends each non-empty output viewshed
  //value to a ball centered at that point
  interpolate_raster(outgrid, output_name); 
#endif

  exit(0); 
}
示例#13
0
文件: vcfquery.c 项目: msto/pysam
int main_vcfquery(int argc, char *argv[])
{
    int c, collapse = 0;
    args_t *args = (args_t*) calloc(1,sizeof(args_t));
    args->argc   = argc; args->argv = argv;
    int regions_is_file = 0, targets_is_file = 0;

    static struct option loptions[] =
    {
        {"help",0,0,'h'},
        {"list-samples",0,0,'l'},
        {"include",1,0,'i'},
        {"exclude",1,0,'e'},
        {"format",1,0,'f'},
        {"output-file",1,0,'o'},
        {"regions",1,0,'r'},
        {"regions-file",1,0,'R'},
        {"targets",1,0,'t'},
        {"targets-file",1,0,'T'},
        {"annots",1,0,'a'},
        {"samples",1,0,'s'},
        {"samples-file",1,0,'S'},
        {"print-header",0,0,'H'},
        {"collapse",1,0,'c'},
        {"vcf-list",1,0,'v'},
        {"allow-undef-tags",0,0,'u'},
        {0,0,0,0}
    };
    while ((c = getopt_long(argc, argv, "hlr:R:f:a:s:S:Ht:T:c:v:i:e:o:u",loptions,NULL)) >= 0) {
        switch (c) {
            case 'o': args->fn_out = optarg; break;
            case 'f': args->format_str = strdup(optarg); break;
            case 'H': args->print_header = 1; break;
            case 'v': args->vcf_list = optarg; break;
            case 'c':
                if ( !strcmp(optarg,"snps") ) collapse |= COLLAPSE_SNPS;
                else if ( !strcmp(optarg,"indels") ) collapse |= COLLAPSE_INDELS;
                else if ( !strcmp(optarg,"both") ) collapse |= COLLAPSE_SNPS | COLLAPSE_INDELS;
                else if ( !strcmp(optarg,"any") ) collapse |= COLLAPSE_ANY;
                else if ( !strcmp(optarg,"all") ) collapse |= COLLAPSE_ANY;
                else if ( !strcmp(optarg,"some") ) collapse |= COLLAPSE_SOME;
                else error("The --collapse string \"%s\" not recognised.\n", optarg);
                break;
            case 'a':
                {
                    kstring_t str = {0,0,0};
                    kputs("%CHROM\t%POS\t%MASK\t%REF\t%ALT\t%", &str);
                    char *p = optarg;
                    while ( *p )
                    {
                        if ( *p==',' )
                            kputs("\t%", &str);
                        else
                            kputc(*p, &str);
                        p++;
                    }
                    kputc('\n', &str);
                    args->format_str = str.s;
                    break;
                }
            case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break;
            case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break;
            case 'r': args->regions_list = optarg; break;
            case 'R': args->regions_list = optarg; regions_is_file = 1; break;
            case 't': args->targets_list = optarg; break;
            case 'T': args->targets_list = optarg; targets_is_file = 1; break;
            case 'l': args->list_columns = 1; break;
            case 'u': args->allow_undef_tags = 1; break;
            case 's': args->sample_list = optarg; break;
            case 'S': args->sample_list = optarg; args->sample_is_file = 1; break;
            case 'h':
            case '?': usage();
            default: error("Unknown argument: %s\n", optarg);
        }
    }

    char *fname = NULL;
    if ( optind>=argc )
    {
        if ( !isatty(fileno((FILE *)stdin)) ) fname = "-";
    }
    else fname = argv[optind];

    if ( args->list_columns )
    {
        if ( !fname ) error("Missing the VCF file name\n");
        args->files = bcf_sr_init();
        if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum));
        list_columns(args);
        bcf_sr_destroy(args->files);
        free(args);
        return 0;
    }

    if ( !args->format_str ) usage();
    args->out = args->fn_out ? fopen(args->fn_out, "w") : stdout;
    if ( !args->out ) error("%s: %s\n", args->fn_out,strerror(errno));

    if ( !args->vcf_list )
    {
        if ( !fname ) usage();
        args->files = bcf_sr_init();
        args->files->collapse = collapse;
        if ( optind+1 < argc ) args->files->require_index = 1;
        if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 )
            error("Failed to read the regions: %s\n", args->regions_list);
        if ( args->targets_list )
        {
            if ( bcf_sr_set_targets(args->files, args->targets_list, targets_is_file, 0)<0 )
                error("Failed to read the targets: %s\n", args->targets_list);
        }
        while ( fname )
        {
            if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum));
            fname = ++optind < argc ? argv[optind] : NULL;
        }
        init_data(args);
        query_vcf(args);
        free(args->format_str);
        destroy_data(args);
        bcf_sr_destroy(args->files);
        fclose(args->out);
        free(args);
        return 0;
    }

    // multiple VCFs
    int i, k, nfiles, prev_nsamples = 0;
    char **fnames, **prev_samples = NULL;
    fnames = hts_readlist(args->vcf_list, 1, &nfiles);
    if ( !nfiles ) error("No files in %s?\n", args->vcf_list);
    for (i=0; i<nfiles; i++)
    {
        args->files = bcf_sr_init();
        args->files->collapse = collapse;
        if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 )
            error("Failed to read the regions: %s\n", args->regions_list);
        if ( optind < argc ) args->files->require_index = 1;
        if ( args->targets_list )
        {
            if ( bcf_sr_set_targets(args->files, args->targets_list,targets_is_file, 0)<0 )
                error("Failed to read the targets: %s\n", args->targets_list);
        }
        if ( !bcf_sr_add_reader(args->files, fnames[i]) ) error("Failed to open %s: %s\n", fnames[i],bcf_sr_strerror(args->files->errnum));
        for (k=optind; k<argc; k++)
            if ( !bcf_sr_add_reader(args->files, argv[k]) ) error("Failed to open %s: %s\n", argv[k],bcf_sr_strerror(args->files->errnum));
        init_data(args);
        if ( i==0 )
            prev_samples = copy_header(args->header, args->files->readers[0].header->samples, bcf_hdr_nsamples(args->files->readers[0].header));
        else
        {
            args->print_header = 0;
            if ( compare_header(args->header, args->files->readers[0].header->samples, bcf_hdr_nsamples(args->files->readers[0].header), prev_samples, prev_nsamples) )
                error("Different samples in %s and %s\n", fnames[i-1],fnames[i]);
        }
        query_vcf(args);
        destroy_data(args);
        bcf_sr_destroy(args->files);
    }
    fclose(args->out);
    destroy_list(fnames, nfiles);
    destroy_list(prev_samples, prev_nsamples);
    free(args->format_str);
    free(args);
    return 0;
}