#include "collect.h"
#include "savant.h"
#include "savutil.h"
#include "yenta-savant.h"

DDV_coll *docs = NULL;

int main(int argc, char **argv)
{
  int tmp, *wts, *wt;
  char **excludees = (char **)malloc(sizeof(char *)*(argc-1));
  char **names, **name, **words;
  float *matches;
  printf("%d.\n", argc);
  core_comm_local();
  load_config("/users/barkalow/.savantrc", 1);
  init_savant_yenta("temp");
  for (tmp = 0; tmp < DVM_rng; tmp++)
    if (DVszs[tmp])
      {
	ddv2description(DocVecs->items[tmp], 0.90, &words, &wts);

	wt = wts;
      
	printf("---\n");
	for (name = words; *name; name++)
	  {
	    printf("%d %s\n", *wt, *name);
	    wt++;
	  }
	printf("---\n");
      }
  /*  memcpy(excludees, argv + 2, sizeof(char *)*(argc-2));
  excludees[argc-2] = NULL;*/
  if (argc > 1)
    {

/*  names = filenames(argv[1]);*/
  names = &argv[1];
  
  for (tmp = 2; tmp < argc; tmp++)
    {
      remove_doc(atoi(argv[tmp]));
      printf("removed %d", atoi(argv[tmp]));
    }

  docs = temp_coll();
  printf("Reported %d.\n", coll_acquire_file(docs, names[0]));
  printf("Got %d document(s) from the first file.\n", docs->length);

  printf("%p\n", &wts);

  for (tmp = 0; tmp < docs->length; tmp++)
    {
      ddv2description(docs->items[tmp], 0.90, &words, &wts);

      wt = wts;
      
      for (name = words; *name; name++)
	{
	  printf("%d %s\n", *wt, *name);
	  wt++;
	}

      printf("%s\n", ddv2string(description2ddv(words, wts), 10));

      printf("%d ?= %d rng: %d max: %d\n",
	     Current_IDnum, DocVecs->length, DVM_rng, DVM_max);

      save_dv(docs->items[tmp]);
    }
  matches = find_matches(docs->items[0]);

  printf("\nComparisons:\n");

  for (tmp = 0; tmp < DVM_rng; tmp++)
    printf("%d %f\n", DVszs[tmp], matches[tmp]);
  free(matches);

  close_coll(docs);
    }
  else
    {
  matches = find_matches(DocVecs->items[0]);

  printf("\nComparisons:\n");

  for (tmp = 0; tmp < DVM_rng; tmp++)
    printf("%d %f\n", DVszs[tmp], matches[tmp]);
  free(matches);
    }
/*
  for (name = names; *name; name++)
    {
      printf("%s\n", *name);
      free(*name);
    }
  free(names);
*/
  /*
  docs = load_coll("foo");
  printf("acquiring...\n");
  coll_acquire(argv[1], &excludees, docs, 100);
  printf("%d docs found.\n", docs->length);
  close_coll(docs);
  for (tmp = argc-2; excludees[tmp]; tmp++)
    {
      printf("%s", excludees[tmp]);
      free(excludees[tmp]);
    }
  free(excludees);
  printf("okay!\n");*/

  close_savant_yenta();
  exit(0);
}
