示例#1
0
main()
{
	int srcrow,srccol,destrow,destcol;
	char filename[FILENAMELENGTH];
	char sinput[10];

	show_menu();

	scanf("%s",sinput);
	while(stricmp(sinput,"q")!=0)
	{
		if(stricmp(sinput,"p")==0)
		{
			printf("$ input src point :  col(a~h) >");
			scanf("%s",sinput);				
			srccol=sinput[0]-96;

			printf("$ input src point :  row(1~8) >");
			scanf("%d",&srcrow);

			printf("$ input dest point : col(a~h) >");
			scanf("%s",sinput);
			destcol=sinput[0]-96;

			printf("$ input dest point : row(1~8) >");
			scanf("%d",&destrow);

			//求解
			knight_walk(srcrow,srccol,destrow,destcol);
			int nMinStep=min_step();

			printf("\nTo get from %c%d to %c%d takes %d knight moves.\n\n",srccol+96,srcrow,destcol+96,destrow,nMinStep);
		}
		else if(stricmp(sinput,"f")==0)
		{
			printf("$ input test file name >");
			scanf("%s",filename);

			//处理测试文件
			process_test_file(filename);
		}

		//输入命令
		printf("$ input command >");
		scanf("%s",sinput);
	}

	return 0;
}
示例#2
0
//In our parameters processing, if the return of getopt_long_only() is 1 we exit, on 0 success, on -1 error
void process_params(int argc, char **argv, parsed_options_t *set_options, test_t **test_list, index_t *test_length, iteration_data_t **iterations, index_t *iterations_length){
  int opt_index;
  int value;
  index_t option_string_length=0;
  char *message_file_path = NULL;
  char *input_file_path = NULL;

  memset(set_options, '\0', sizeof(parsed_options_t));
  set_options->maximum_size = MAXSIZE;
  set_options->minimum_size = MINSIZE;
  set_options->output_file = stdout;

  while(1){
    value = getopt_long_only(argc, argv, "", long_options, &opt_index);
    if(value == -1){
      break;
    }
    switch(value) {
      case 1:
        print_version();
        exit(0);
      case 2:
        print_version();
        print_help();
        exit(0);
      case 3:
        set_options->disable_cache = 1;
        break;
      case 4:
        set_options->warmup_run = 1;
        break;
      case 5:
        option_string_length = strlen(optarg)+1;
        set_options->output_file_path = malloc(option_string_length);
        memcpy(set_options->output_file_path, optarg, option_string_length);
        break;
      case 7:
        option_string_length = strlen(optarg)+1;
        message_file_path = malloc(option_string_length);
        memcpy(message_file_path, optarg, option_string_length);
        break;
      case 8:
        set_options->minimum_size = process_string_to_number(optarg);
        break;
      case 9:
        set_options->maximum_size = process_string_to_number(optarg);
        break;
      case 10:
        set_options->run_time = process_string_to_number(optarg);
        break;
      case 11:
        option_string_length = strlen(optarg)+1;
        input_file_path = malloc(option_string_length);
        memcpy(input_file_path, optarg, option_string_length);
        break;
      case 12:
        set_options->affinity_test = 1;
        if(N_PES != 2){
          fprintf(stderr, "The --affinity flag requires the use of exactly 2 PEs!\n");
          abort();
        }
        break;
      case '?':
        break;
      default:
        fprintf(stderr, "Unknown option 0%o\n", value);
    }
  }

  init_tests();

  if(set_options->output_file_path != NULL) {
    set_options->output_file = fopen(set_options->output_file_path, "w");
  }

  if(input_file_path != NULL){
    process_test_file(input_file_path, test_list, test_length, set_options);
    free(input_file_path);
  } else {
    if(set_options->affinity_test == 0){
      *test_length = all_tests(test_list);
      if(shmem_my_pe() == 0)fprintf(set_options->output_file, "Created all test list.\n");
    } else {
      *test_length = affinity_tests(test_list);
      if(shmem_my_pe() == 0)fprintf(set_options->output_file, "created affinity test list.\n");
    }
  }

  if(shmem_my_pe() == 0) fprintf(set_options->output_file, "Will be running with %lu different tests\n", (*test_length));

  if(message_file_path != NULL) {
    process_iteration_file(message_file_path, iterations, iterations_length);
    free(message_file_path);
  } else {
    *iterations_length = init_iterations(iterations, set_options->minimum_size, set_options->maximum_size);
  }

  if(shmem_my_pe() == 0) fprintf(set_options->output_file, "Will be running with %lu different size configurations\n", (*iterations_length));
}