/**
 * Analyse whatever contract is provided and respond
 *
 * Do not free to_analyse
 * The return value is also freed elsewhere.
 *
 * \param to_analyse The contract to analyse.
 * \param ccr The contract completion report to populate
 * \returns 0 on success, -1 on error
 */
int analyse_contract(contract_t to_analyse, contract_completion_report_t ccr)
{
  is_contiguous = contract_is_contiguous(to_analyse);
  absolute_offset = contract_get_absolute_offset(to_analyse);

  const char *path = contract_get_path(to_analyse);

  result_t new_result = result_init(NULL, 0);

  result_set_confidence(new_result, 0);
  result_set_subcontractor_name(new_result, PROCESS_NAME);
  result_set_brief_data_description(new_result, "Garbage");
  result_set_data_description(new_result, "Not properly detected");

  int ret = process_file(path, new_result);

  contract_completion_report_add_result(ccr, new_result);

  if (ret != 0)
  {
    debug_log("analyse_contract produced no result");
  }
  result_close(new_result);

  return 0;
}
示例#2
0
文件: run.c 项目: testfarm/testfarm
int run_init(periph_t *periph, int argc, char **argv, int interactive, char *wait)
{
  /* Open WAIT synchronization output */
  if ( wait != NULL ) {
    char *err;
    int fd = strtol(wait, &err, 10);

    if ( (err != NULL) && (*err > ' ') )
      fd = -1;

    if ( fd >= 0 ) {
      if ( (run_wait_output = fdopen(fd, "w")) == NULL ) {
        fprintf(stderr, NAME ": Cannot open WAIT synchronization output fd=%d: %s\n", fd, strerror(errno));
        return -1;
      }
    }
    else {
      if ( (run_wait_output = fopen(wait, "w")) == NULL ) {
        fprintf(stderr, NAME ": Cannot open WAIT synchronization output %s: %s\n", wait, strerror(errno));
        return -1;
      }
    }

    setbuf(run_wait_output, NULL);

    /* Child programs should not have access this file descriptor */
    fcntl(fileno(run_wait_output), F_SETFD, FD_CLOEXEC);
  }

  /* Store peripheral descriptor address */
  run_periph = periph;

  /* Setup runtime log gears */
  if ( result_init() )
    return -1;

  /* Create shell engine */
  run_shell = shell_alloc(NAME, argc, argv, NULL);

  /* Set interactive mode */
  shell_set_interactive(run_shell, interactive);

  /* Setup prologue routine */
  shell_set_prologue(run_shell, run_prologue, NULL);

  /* No input echo */
  shell_set_input_echo(run_shell, NULL, NULL);

  /* Setup special commands */
  shell_set_cmd(run_shell, run_commands);

  /* Setup standard commands, standard header routine, help table */
  shell_std_set_header(result_header_engine);
  shell_std_set_echo(run_exec_echo);
  shell_std_set_unknown(run_exec_unknown);
  shell_std_setup(run_shell, run_help);

  return 0;
}
示例#3
0
int resultmodel_clear(ResultModel* prModel) {
    int i = 0;
    if (prModel == NULL) {
        return RESULTMODEL_NULLPTR;
    }
    for (i = 0; i < RESULTMODEL_SIZE; i++) {
        if (result_init(&prModel->result[i]) < 0) {
            return RESULTMODEL_FAILURE;
        }
    }
    prModel->count = 0;
    return RESULTMODEL_SUCCESS;
}
示例#4
0
result_t* play(uint8_t board_size, neuralnet_t* black, neuralnet_t* white, uint8_t komi, FILE* record)
{
	board_t* board = board_create(board_size);
	bool game_over = false;
	int8_t passed  = 0;
	result_t* final = result_init(black, white);

	//Game loop
	while(game_over == false)
	{
		move_t* move = genmove(board, final);
			
			//No move left
			if(move->x == -1)
			{
				game_over = true;
				break;
			}
			//Pass
			else if(move->x >= board_size)
			{
				board_pass(board);
				++passed;
				if(passed > 1)
				{
					game_over = true;
					break;
				}
			}
			//Placement
			else
			{
				write_move(record, board->turn, (uint8_t)move->x, (uint8_t)move->y);
				board_place(board, (uint8_t)move->x, (uint8_t)move->y);
				passed = 0;
			}
	}
	
	//Scoring
	int score_val = board_score(board);
	final->score_black = score_val;
示例#5
0
/**
 * Analyse contract and respond
 *
 * Attempts to parse the supplied file as JBIG
 *
 * \param to_analyse The contract to analyse
 * \param ccr The contract completion report to populate
 * \returns 0 on sucess, -1 on error
 */
int analyse_contract(contract_t to_analyse, contract_completion_report_t ccr)
{
  struct jbg_dec_state sd;
  unsigned char data[JHEAD_SIZE];
  int status;
  size_t cnt;

  const char *path = contract_get_path(to_analyse);

  jbg_dec_init(&sd);
  FILE *file = fopen(path, "r");

  if (file == NULL)
  {
    warning_log("analyse_contract: Could not open file");
    return 0;
  }

  /* Read header and check for valid JBIG */
  int size = 0;

  size = fread(&data, BYTE, JHEAD_SIZE, file);
  status = jbg_dec_in(&sd, data, JHEAD_SIZE, &cnt);

  if (status >= JBG_EINVAL && status <= (JBG_EINVAL | 14))
  {
    debug_log("Not a valid JBIG file");
    jbg_dec_free(&sd);
    return 0;
  }

  /* Read in the whole JBIG */
  int bytes_read;

  while ((bytes_read = fread(&data, BYTE, BYTE, file)))
  {
    size += bytes_read;
    status = jbg_dec_in(&sd, data, BYTE, &cnt);

    if (status == JBG_EOK)
    {                           /* Found end of file */
      break;
    } else if (status != JBG_EAGAIN)
    {                           /* Error value returned */
      debug_log("Error reading JBIG: %s", jbg_strerror(status));
      jbg_dec_free(&sd);
      return 0;
    } else if (size == 104857600)
    {                           /* Only read upto 100MB */
      debug_log("Read 100MB, couldnt find end of JBIG");
      jbg_dec_free(&sd);
      return 0;
    }
  }
  fclose(file);

  /* Process loaded JBIG */
  gchar *hxw = g_strdup_printf("%ldx%ld", jbg_dec_getwidth(&sd), jbg_dec_getheight(&sd));
  gchar *planes = g_strdup_printf("%d plane(s)", jbg_dec_getplanes(&sd));
  gchar *bytes = g_strdup_printf("%dB", size);

  gchar *data_str = g_strdup_printf("%s, %s, %s", bytes, hxw, planes);

  g_free(hxw);
  g_free(planes);
  g_free(bytes);

  /* Fill in report and result data, identifying blocks if possible */
  long long int offset = contract_get_absolute_offset(to_analyse);
  int contig = contract_is_contiguous(to_analyse);

  result_t result = result_init(NULL, 0);

  populate_result_with_length(result, "JBIG", data_str, 100, offset, size, contig);
  contract_completion_report_add_result(ccr, result);
  result_close(result);

  g_free(data_str);

  return 0;
}