Example #1
0
int main()
{
  int ret = 0;
  list_t terms;
  search_t search;

  SIGCATCH_INIT

  memset(&terms, 0x0, sizeof(list_t));
  memset(&search, 0x0, sizeof(search_t));

  /* simple match */
  list_item_add(&terms, "alice", 0);
  list_item_add(&terms, "mary", 0);

  ret = search_parse_terms(&search, &terms);
  assert(ret == 0);

  assert(search_match_substr(&search, "test1 test2 test3") == 0);
  assert(search_match_substr(&search, " alice mary ") == 1);
  assert(search_match_substr(&search, " alice rose ") == 0);
  assert(search_match_substr(&search, " alice mary bob") == 1);
  assert(search_match_substr(&search, " alice rosemary ") == 1);
  assert(search_match_substr(&search, " alice rosemary bob ") == 1);

  list_clear(&terms);
  search_free(&search);

  /* more complex examples */
  list_item_add(&terms, "alice", 0);
  assert(search_parse_terms(&search, &terms) == 0);
  assert(search_match_substr(&search, " alice ") == 1);
  assert(search_match_substr(&search, "malice") == 1);
  assert(search_match_substr(&search, " mary ") == 0);
  list_clear(&terms);
  search_free(&search);

  list_item_add(&terms, "~mary", 0);
  assert(search_parse_terms(&search, &terms) == 0);
  assert(search_match_substr(&search, " alice ") == 1);
  assert(search_match_substr(&search, " mary ") == 0);
  assert(search_match_substr(&search, "mary") == 0);
  assert(search_match_substr(&search, "rosemary") == 0);
  assert(search_match_substr(&search, " rosemary ") == 0);
  list_clear(&terms);
  search_free(&search);

  return 0;
}
Example #2
0
int main()
{
  int ret = 0;
  list_t terms;
  search_t search;

  SIGCATCH_INIT

  memset(&terms, 0x0, sizeof(list_t));
  memset(&search, 0x0, sizeof(search_t));

  /* simple match */
  list_item_add(&terms, "alice", 0);
  list_item_add(&terms, "+mary", 0);
  list_item_add(&terms, "-bob", 0);

  ret = search_parse_terms(&search, &terms);
  assert(ret == 0);

  /* motto: nobody loves bob */
  assert(search_match_exact(&search, "test1 test2 test3") == 0);
  assert(search_match_exact(&search, " alice mary ") == 1);
  assert(search_match_exact(&search, " alice rose ") == 0);
  assert(search_match_exact(&search, " alice mary bob ") == 0);
  assert(search_match_exact(&search, " alice rosemary ") == 0);
  assert(search_match_exact(&search, " alice rosemary bob ") == 0);
  assert(search_match_exact(&search, " alice mary robert ") == 1);
  assert(search_match_exact(&search, " malice rosemary robert ") == 0);

  list_clear(&terms);
  search_free(&search);

  return 0;
}
Example #3
0
int batch_decoder_free(batch_decoder_t *bd)
{
    hash_iter_t *itor;
    if (bd == NULL)
        return 0;
    if (bd->ctlfh != NULL)
        fclose(bd->ctlfh);
    if (bd->alignfh != NULL)
        fclose(bd->alignfh);
    if (bd->hypfh != NULL)
        fclose(bd->hypfh);
    cmd_ln_free_r(bd->config);
    search_free(bd->fwdtree);
    search_free(bd->fwdflat);
    //search_free(bd->latgen);
    search_factory_free(bd->sf);
    for (itor = hash_table_iter(bd->hypfiles); itor; itor
            = hash_table_iter_next(itor)) {
        fclose(hash_entry_val(itor->ent));
    }
    hash_table_free(bd->hypfiles);
    ckd_free(bd);
    return 0;
}
Example #4
0
int main()
{
  int ret = 0;
  list_t terms;
  search_t search;

  SIGCATCH_INIT

  memset(&terms, 0x0, sizeof(list_t));
  memset(&search, 0x0, sizeof(search_t));

  list_item_add(&terms, "fred", 0);
  list_item_add(&terms, "~velma", 0);
  list_item_add(&terms, "+dafna", 0);
  list_item_add(&terms, "-shaggy", 0);
#ifdef REGEX_SEARCH
  list_item_add(&terms, "-/[ck]tulhu/", 0);
  list_item_add(&terms, "/nyan_cat/i", 0);
#endif

  ret = search_parse_terms(&search, &terms);
  assert(ret == 0);
  assert(search.substr.items == 3);
  assert(search.exact.items  == 2);
  assert(memcmp(search.substr.buf, "+fred\0-velma\0+dafna\0", 6 + 7 + 7) == 0);
  assert(memcmp(search.exact.buf,  "+ dafna \0- shaggy \0", 9 + 10) == 0);
#ifdef REGEX_SEARCH
  assert(search.regex_cnt == 2);
  assert(search.regex_neg[0] == true);
  assert(search.regex_neg[1] == false);
  assert(search.regex_neg[2] == false);
  assert(memcmp(&search.regexps[0], &search.regexps[2], sizeof(regex_t)) != 0);
  assert(memcmp(&search.regexps[1], &search.regexps[2], sizeof(regex_t)) != 0);
#endif

  search_free(&search);

  return 0;
}
Example #5
0
File: vmm.c Project: PSanf2/POS_C9
u32int *malloc_above(u32int size, u32int align, u32int above)
{
	list_node_type *malloc_node = search_free((size + align), above);
	
	vmm_data_type *malloc_data = malloc_node->data;
	
	u32int start_addr = malloc_data->virt_addr;
	u32int split_size = 0;
	
	while (start_addr < above)
	{
		start_addr++;
		split_size++;
	}
	
	while (start_addr % align != 0)
	{
		start_addr++;
		split_size++;
	}
	
	if (split_size > 0)
	{
		malloc_node = split_free(malloc_node, size);
		malloc_node = malloc_node->next;
	}
	
	list_node_type *split_node = split_free(malloc_node, size);
	
	remove(vmm_free, split_node);
	
	insert_last(vmm_used, split_node);
	
	vmm_data_type *malloc_node_data = (vmm_data_type *) malloc_node->data;
	u32int *malloc_ptr = (u32int *) malloc_node_data->virt_addr;
	
	return malloc_ptr;
}
Example #6
0
/**
 * @brief edax main function.
 *
 * Do a global initialization and choose a User Interface protocol.
 *
 * @param argc Number of arguments.
 * @param argv Command line arguments.
 */
int main(int argc, char **argv)
{
	UI *ui;
	int i, r, level = 0, size = 8;
	char *problem_file = NULL;
	char *wthor_file = NULL;
	char *count_type = NULL;
	int n_bench = 0;

	// options.n_task default to system cpu number
	options.n_task = get_cpu_number();

	// options from edax.ini
	options_parse("edax.ini");

	// allocate ui
	ui = (UI*) malloc(sizeof *ui);
	if (ui == NULL) fatal_error("Cannot allocate a user interface.\n");
	ui->type = UI_EDAX;
	ui->init = ui_init_edax;
	ui->free = ui_free_edax;
	ui->loop = ui_loop_edax;

	// parse arguments
	for (i = 1; i < argc; i++) {
		char *arg = argv[i];
		while (*arg == '-') ++arg;
		if (strcmp(arg, "v") == 0 || strcmp(arg, "version") == 0) version();
		else if (ui_switch(ui, arg)) ;
		else if ((r = (options_read(arg, argv[i + 1]))) > 0) i += r - 1;
		else if (strcmp(arg, "solve") == 0 && argv[i + 1]) problem_file = argv[++i];
		else if (strcmp(arg, "wtest") == 0 && argv[i + 1]) wthor_file = argv[++i];
		else if (strcmp(arg, "bench") == 0 && argv[i + 1]) n_bench = atoi(argv[++i]);
		else if (strcmp(arg, "count") == 0 && argv[i + 1]) {
			count_type = argv[++i];
			if (argv[i + 1]) level = string_to_int(argv[++i], 0);
			if (argv[i + 1] && strcmp(argv[i + 1], "6x6") == 0) {
				size = 6;
				++i;
			}
			
	
		}
		else usage();
	}
	options_bound();

	// initialize
	edge_stability_init();
	hash_code_init();
	hash_move_init();
	statistics_init();
	eval_open(options.eval_file);
	search_global_init();

	// solver & tester
	if (problem_file || wthor_file || n_bench) {
		Search search[1];
		search_init(search);
		search->options.header = " depth|score|       time   |  nodes (N)  |   N/s    | principal variation";
		search->options.separator = "------+-----+--------------+-------------+----------+---------------------";
		if (options.verbosity) version();
		if (problem_file) obf_test(search, problem_file, NULL);
		if (wthor_file) wthor_test(wthor_file, search);
		if (n_bench) obf_speed(search, n_bench);
		search_free(search);

	} else if (count_type){
		Board board[1];
		board_init(board);
		if (strcmp(count_type, "games") == 0) quick_count_games(board, level, size);		
		else if (strcmp(count_type, "positions") == 0) count_positions(board, level, size);		
		else if (strcmp(count_type, "shapes") == 0) count_shapes(board, level, size);		

	} else if (ui->type == UI_CASSIO) {
		engine_loop();

	// other protocols
	} else {
		ui_event_init(ui);
		ui->init(ui);
		ui->loop(ui);
		if (ui->free) ui->free(ui);
		ui_event_free(ui);
	}

	// display statistics
	statistics_print(stdout);


	// free;
	eval_close();
	options_free();
	free(ui);

	return 0;
}