Ejemplo n.º 1
0
Archivo: se.c Proyecto: oracc/owi
int
main(int argc, char * const*argv)
{
  struct token *toks = NULL;
  int ntoks = 0;
  static struct Datum result;

  f_log = stderr;
  exit_on_error = TRUE;
  setlocale(LC_ALL,LOCALE);
  options(argc, argv, "28cdg:o:p:P:stuvx:");
  if (!out_f)
    out_f = stdout;

  if (doing_debug)
    f_log = fopen("se.dbg","w");

  /*atf2utf8_init();*/
  charsets_init();
  langtag_init();
  tokinit();

  if (pretrim_file || pretrim_args)
    pretrim_setup();

  if (xmldir)
    toks = tokenize(xmldir_toks(xmldir),&ntoks);
  else
    toks = tokenize((const char **)(argv+optind),&ntoks);
  if (show_tokens)
    {
      showtoks(toks,ntoks);
    }
  else
    {
      binop_init();
      binop24_init();
      result = evaluate(toks, -1, lm_any, NULL);
      progress("se: result.count == %lu\n", (unsigned long)result.count);

      if (do_uniq && (res_gran == g_word || res_gran == g_grapheme))
	do_uniq = 0;

      if (do_uniq && result.count > 1)
	{
	  uniq(&result);
	  progress("se: post-uniq result.count == %lu\n", (unsigned long)result.count);
	}
      if (show_count)
	printf("%lu\n",(unsigned long)result.count);
      else if (result.count)
	{
	  if (xmldir)
	    xmldir_results(xmldir,result.count);
	  if ('v' == id_prefix(result.l.l8p[0]->text_id))
	    {
	      if (!strcmp(return_index, "cat"))
		vid_display_proj = vid_proj_xmd;
	      else
		vid_display_proj = vid_proj_xtf;
	      vid_show_results(&result);
	    }
	  else
	    show_results(&result);
	}
      else if (xmldir)
	xmldir_results(xmldir,result.count);
    }
  if (pretrim_args)
    {
      list_free(pretrim_args, NULL);
      pretrim_args = NULL;
    }
  if (pretrim)
    {
      hash_free(pretrim, NULL);
      pretrim = NULL;
      free(pretrim_lines);
      free(pretrim_content);
      pretrim_content = NULL;
      pretrim_lines = NULL;
    }
  langtag_term();
  return 0;
}
Ejemplo n.º 2
0
int
main(int argc, char * const*argv)
{
  struct token *toks = NULL;
  int ntoks = 0;

  f_log = stderr;
  exit_on_error = TRUE;
  setlocale(LC_ALL,LOCALE);
  options(argc, argv, "28acdg:j:o:p:P:stuvx:");
  if (!out_f)
    out_f = stdout;

  if (doing_debug)
    f_log = fopen("se.dbg","w");

  /*atf2utf8_init();*/
  charsets_init();
  langtag_init();
  tokinit();

  if (pretrim_file || pretrim_args)
    pretrim_setup();

  if (show_tokens)
    {
      if (xmldir)
	toks = tokenize(xmldir_toks(xmldir),&ntoks);
      else
	toks = tokenize((const char **)(argv+optind),&ntoks);
      showtoks(toks,ntoks);
    }
  else
    {
      if (any_index)
	{
	  const char *index[] = { "!cat" , "!txt" , "!tra" , "!lem", NULL, "!esp" , NULL };
	  struct Datum results[4];
	  int i, best_findset = -1;
	  char *hashproj = NULL;
	  FILE *anyout = stdout;
	  const char **toklist = NULL;

	  if (!project)
	    {
	      fprintf(stderr, "se: must give -j PROJECT option when using -a\n");
	      exit(1);
	    }

	  if (xmldir)
	    {
	      char *anyfile = malloc(strlen(xmldir)+5);
	      sprintf(anyfile,"%s/any",xmldir);
	      anyout = xfopen(anyfile,"w");
	    }

	  hashproj = malloc(strlen(project) + 2);
	  sprintf(hashproj, "#%s",project);

	  for (i = 0; index[i]; ++i)
	    {
	      if (!strcmp(index[i], "!lem"))
		{
		  if (best_findset > 0)
		    continue;
		}

	      toklist = anytoks(hashproj, index[i],
				xmldir ? xmldir_toks(xmldir) : (const char **)(argv+optind));
	      toks = tokenize(toklist,&ntoks);
	      /*showtoks(toks,ntoks);*/
	      run_search(toks);
	      results[i] = result;
	      if (result.count
		  && (best_findset < 0 
		      || (best_findset >= 0 && results[best_findset].count < result.count)))
		{
		  best_findset = i;
		  best_res_gran = res_gran;
		}
	    }
	  if (best_findset >= 0)
	    {
	      fprintf(anyout, "%s %lu\n", index[best_findset], 
		      (unsigned long)results[best_findset].count);
	      for (i = 0; index[i]; ++i)
		{
		  if (i == best_findset)
		    continue;
		  if (results[i].count)
		    fprintf(anyout, "%s %lu\n", index[i], (unsigned long)results[i].count);
		}
	      res_gran = best_res_gran;
	      return_index = &index[best_findset][1];
	      put_results(&results[best_findset]);
	    }
	  else
	    
	  fclose(anyout);
	}
      else
	{
	  toks = tokenize(xmldir ? xmldir_toks(xmldir) : (const char **)(argv+optind),&ntoks);
	  run_search(toks);
	  put_results(&result);
	}
    }

  if (pretrim)
    {
      hash_free(pretrim, NULL);
      pretrim = NULL;
      free(pretrim_lines);
      free(pretrim_content);
      pretrim_content = NULL;
      pretrim_lines = NULL;
      if (pretrim_args)
	{
	  list_free(pretrim_args, NULL);
	  pretrim_args = NULL;
	}
    }
  langtag_term();

  return 0;
}