Esempio n. 1
0
int
main(int argc, char **argv)
{
    if (argc <= 1) {
	fprintf(stderr, "Usage:\n");
	fprintf(stderr, "%s <options> <benchmark>\n", argv[0]);
	exit(1);
    }

    init_isa();
    // read options including (1) actions; (2) processor configuration
    read_opt(argc, argv);
    
    /* liangyun: read jump table if necessary */   
    read_injp(argv[argc - 1]);

    /* liangyun: read depth table for recursive function */
    read_recursive(argv[argc - 1]);
 
    path_analysis(argv[argc-1]);
    
    if (strcmp(run_opt, "CFG") == 0)
	run_cfg(argv[argc - 1]);
    else
	run_est(argv[argc - 1]);
}
Esempio n. 2
0
static int get_str(char *buffer, size_t buffer_size)
{
	int ret = 0;
	char ch;
	uint8_t loop = 1;
	char *s;
	int i = 0;

	s = buffer;

	do {
		ch = read_opt();
		switch (ch) {
			case '\r':
				/* enter */
				*s = 0;
				loop = 0;
				break;

			case CTRL_C:
				loop = 0;
				ret = USER_CANCEL;

			case 0x08:
				/* backspace */
				if ( i ) {
					printf("\b \b");
					i--;
					s--;
				}
				break;

			default:
				/* Don't let buffer to overrun */
				if ( i != (buffer_size - 1) )
				{
					printf("%c", ch);
					*s = ch;
					i++;
					s++;
				}
				break;
		}
	} while ( loop );

	return ret;
}
Esempio n. 3
0
static int run_menu(const menu_opt_t menu[], const int entries)
{
        int ret, exit_menu = 0;

	do {
		print_menu(menu, entries);

		ret = read_opt();
                if (ret ==  CTRL_C)
			exit_menu = 1;
		else {
			printf("%c\n", ret);
			ret = process_menu_otpion(menu, entries, ret);
			if (CTRL_C == ret || ret == USER_CANCEL)
				exit_menu = 1;
			else
				exit_menu = !ret;
		}
	} while (!exit_menu);
	return ret;
}
Esempio n. 4
0
int main(){
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	int istep, nstep, outp_size;
	double t, tmax;

	std::string name("state");
	read_grid("KIRPICH.GRD");
	read_val("initval");
	read_opt("opt", nstep, tmax, outp_size);
	
	if(!recover("schG1.ini", istep, t)){istep = 0;	t = 0;}
	show(name);
	while(istep < nstep || t < tmax){
		step(t);
		istep++;
		std::stringstream ss; ss<<istep;
		std::string s(name);		s.append(ss.str());
		show(s);
	}

	free_all();
	return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
	int          tmode, ans_fi, target, fold, knum;
	unsigned int seed;
	int          tflag = 0, eval_time = 0, skip_flag = 0;
	double       ans_value;
	Data         dat;
	FInfo        fs;

	/* 引数の読み込み */
	read_opt(argc, argv, &dat, &fs, SBS, &tmode, &knum, &fold, &seed);

	/* 各分割におけるデータの個数を初期化 */
	dat.split_num = set_split(fold, dat.total);

	/* 配列の初期化 */
	alloc_prm(&dat, &fs);

	/* データの読み込み */
	read_data(&dat);

	/* 実験の初期化 */
	shuffle(&dat, seed);
	skip_flag = init_step(&dat, &fs, &eval_time, INITIAL, fold, knum, SBS);
	
	if(!skip_flag){
		/* SBS開始 */
		while(1){
			/* 
				 Backward Step: 
				 SBSで評価関数の値を最も少なく減少させる特徴を一つ削除する。
				 削除したらFoward Stepへ。 
			*/
			sbs(&dat, &fs, &ans_value, fold, &target, &eval_time, knum);
			ans_fi = target;
			
			/* 最も不要な特徴を除いた特徴集合を作成 */
			remove_one(&fs, target, ans_value);
			
			print_fs(&fs, eval_time, BACKWARD);
			
			/* tmodeモードの時は、最も評価関数の値が大きい特徴集合を保存する */
			if(tmode)
				eval_best(&fs);
			
			if(fs.sel.num == fs.ext_num){
				print_fs(&fs, eval_time, FINAL);
				tflag = 1;
				break;
			}
			
		};  /* 全体のループ */
	}
	
	/* 選択した特徴集合を出力する */
	output(&fs, tmode, eval_time);
	
	/* 確保した配列を解放する */
	free_prm(&dat, &fs);

	exit(0);
}
Esempio n. 6
0
static int set_custom_nv_settings(const struct menu_opt *menu)
{
	int ret = 0;
	nv_lcd_config_t lcd_config;
	nv_lcd_config_data_t *lcd_config_data;
	uint8_t config_index;
	uint32_t temp;
	char ch;

	ret = LCDConfigRead(&lcd_config);
	switch ( ret )
	{
		/* OK */
		case 0:
			break;

		/* LCD configuration read error, try to create it */
		case 1:
			printf("\n***No valid LCD configuration found!\n");

			break;

		/* LCD config has an invalid size, resize it */
		case 2:
			do {
				printf("\n***Invalid LCD configuration! It is necessary to recreate " \
				"the configuration.\nIf you continue, you will lose your existing settings.\n");
				printf("Do you want to continue (y/n)? ");

				ch = read_opt();
				printf("%c\n", ch);
				if ( (ch == USER_CANCEL) || (ch == 'n') ) {
					goto error;
				}

			} while ( ch != 'y' );

			break;

		default:
			goto error;
	}

	if ( ret > 0 ) {
		printf("\nCreating LCD configuration... ");
		LCDConfigAdd();

		/* Try again to read config */
		if ( LCDConfigRead(&lcd_config) > 0 ) {
			printf("*** Couldn't read LCD configuration from NVRAM\n");
			goto error;
		}
		printf("OK\n\n");
	}

	if ( lcd_config.header.version < NV_LCD_CONFIG_VERSION ) {
		printf("\n*** Invalid LCD configuration version (%d instead of %d).\nConfiguration is resetted!\n\n",
		       lcd_config.header.version, NV_LCD_CONFIG_VERSION);
		LCDConfigReset(&lcd_config);
	}

	if ( !strncmp(menu->param, "custom4_nv", 13) ) {
		lcd_config_data = &lcd_config.lcd2;
		config_index = 2;
	}
	else {
		lcd_config_data = &lcd_config.lcd1;
		config_index = 1;
	}

	/* Get refresh rate */
	if ( (ret = get_uint("  Refresh rate (Hz)", &lcd_config_data->video_mode.refresh, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get Xres */
	if ( (ret = get_uint("  X-resolution (pixels)", &lcd_config_data->video_mode.xres, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get Yres */
	if ( (ret = get_uint("  Y-resolution (pixels)", &lcd_config_data->video_mode.yres, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get pixel clock */
	if ( (ret = get_uint("  Pixel clock (picoseconds)", &lcd_config_data->video_mode.pixclock, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get left margin */
	if ( (ret = get_uint("  Left margin (clocks)", &lcd_config_data->video_mode.left_margin, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get right margin */
	if ( (ret = get_uint("  Right margin (clocks)", &lcd_config_data->video_mode.right_margin, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get upper margin */
	if ( (ret = get_uint("  Upper margin (lines)", &lcd_config_data->video_mode.upper_margin, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get lower margin */
	if ( (ret = get_uint("  Lower margin (lines)", &lcd_config_data->video_mode.lower_margin, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get HSync */
	if ( (ret = get_uint("  H-sync (clocks)", &lcd_config_data->video_mode.hsync_len, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get VSync */
	if ( (ret = get_uint("  V-sync (lines)", &lcd_config_data->video_mode.vsync_len, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get sync */
	if ( (ret = get_uint("  Sync", &lcd_config_data->video_mode.sync, 16, 1,
		syncHelpTable, sizeof(syncHelpTable) / sizeof(help_info_t))) != 0 ) {
		goto error;
	}

	/* Get vmode */
	if ( (ret = get_uint("  V-Mode", &lcd_config_data->video_mode.vmode, 10, 1,
		vmodeHelpTable, sizeof(vmodeHelpTable) / sizeof(help_info_t))) != 0 ) {
		goto error;
	}

	/* Get flags */
	if ( (ret = get_uint("  Flags", &lcd_config_data->video_mode.flag, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Backlight function is enabled */
	temp = lcd_config_data->is_bl_enable_func;
	if ( (ret = get_uint("  Backlight function enabled", &temp, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}
	lcd_config_data->is_bl_enable_func = (temp != 0);

	printf("\nWindows CE specific settings:\n");

	/* Get pixel data offset */
	if ( (ret = get_uint("  Pixel Data Offset", &lcd_config_data->pix_cfg.pix_data_offset, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get pixel clock up */
	if ( (ret = get_uint("  Pixel Clock Up", &lcd_config_data->pix_cfg.pix_clk_up, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	/* Get pixel clock down */
	if ( (ret = get_uint("  Pixel Clock Down", &lcd_config_data->pix_cfg.pix_clk_down, 10, 1,
		NULL, 0)) != 0 ) {
		goto error;
	}

	if ( config_index == 1 ) {
		lcd_config.header.lcd1_valid = 1;
	}
	else {
		lcd_config.header.lcd2_valid = 1;
	}

	if ( LCDConfigWrite(&lcd_config) == 0 ) {
		printf("\n***Couldn't write config into the NVRAM!\n");
		ret = 1;
		goto error;
	}

	if ( NvEnvUpdateLCDConfig() == 0 ) {
		printf("\n***Couldn't update shared memory\n");
		ret = 1;
		goto error;
	}

	return set_video_lcd(menu);

error:
	return ret;
}
Esempio n. 7
0
int main (int argc, char* const argv[])
{
    ssize_t bufsz = 0, niter = 0;
    const char *fname = NULL;
    int rc = 0;
    struct test_spec sp;

    static const int MIN_ARGC = 3;

    if (argc < MIN_ARGC) {
        usage_exit (argv[0]);
    }

    (void) memset (&sp, 0, sizeof(sp));
    rc = read_opt (argc, argv, &sp);
    if (rc) return EINVAL;
    /* uses getopt, exposes optind*/

    if (argc < (optind +  2)) { /* expecting at least 2 more arguments */
        (void) fprintf (stderr, "%s: expecting 2 mandatory parameters "
            "after option flags\n", argv[0]);
        usage_exit (argv[0]);
    }

    fname = argv[optind];
    ++optind;

    bufsz = (ssize_t) atol (argv[optind]);
    if ((bufsz < (ssize_t)MIN_BUFSZ) || (bufsz > (ssize_t)MAX_BUFSZ)) {
        (void) fprintf (stderr, "%s: buffer size [%s] must be within [%ld .. %ld] range\n",
            argv[0], argv[optind], (long)MIN_BUFSZ, (long)MAX_BUFSZ);
        return EINVAL;
    }
    sp.len = bufsz;
    ++optind;

    if (0 >= (niter = (ssize_t) atol (argv[optind]))) {
        (void) fprintf (stderr, "%s: invalid value for niter: %s\n",
            argv[0], argv[optind]);
        return EINVAL;
    }
    sp.niter = niter;
    ++optind;


    if (!sp.len)   sp.len     = MIN_BUFSZ;
    if (!sp.incr)  sp.incr    = MIN_INCR;
    if (!sp.nincr) sp.nincr   = MIN_NINCR;

    if (sp.num_chunks >= sp.len) {
        (void) fprintf (stderr, "%s: number of chunks (-U option) [%ld] "
            "should not exceed buffer size [%ld]\n", argv[0],
            (long)sp.num_chunks, (long)sp.len);
        return EINVAL;
    }

    setbuf (stdout, NULL);
    rc = run_odsync (fname, &sp);

    return rc;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	/**
     * Create binary searches predefined by file type (look into its header). For example: all the PDF files
    */
	DirTreeReader *dtr {};
	std::vector<std::bitset<8>> vecPat;
	unsigned char optField = read_opt(argc, argv, "fl");
	if ((optField & OPTIONS::INVALID) == OPTIONS::INVALID)
	{
		show_usages(argv[0]);
		exit(EXIT_FAILURE);
	}
	else if(((optField & OPTIONS::NONE) == OPTIONS::NONE) && argc == 3)
	{
		if (read_patterns(&vecPat, argv[2]) == -1)
		{
			show_usages(argv[0]);
			exit(EXIT_FAILURE);
		}
		dtr = new DirTreeReader(argv[1]);
	}
	else if(((optField & OPTIONS::NONE) == OPTIONS::NONE) && argc == 4)
	{
		if (read_patterns(&vecPat, argv[3]) == -1)
		{
			show_usages(argv[0]);
			exit(EXIT_FAILURE);
		}
		dtr = new DirTreeReader(argv[2]);
	}
	else
	{
		show_usages(argv[0]);
		exit(EXIT_FAILURE);
	}
	
	
	std::cout << "Number of CPU cores: " << std::thread::hardware_concurrency() << std::endl;
    std::vector<std::string> files = dtr->loadFiles();
	std::cout << "Total files read: " << dtr->getTotalFiles() << std::endl;
	
	
	int offset { -1 };
	std::future<int> fut {};
	BinFinder bf(files.at(0));
	for (uint i = 0; i < files.size(); ++i)
	{
		bf.setFile(files.at(i));
		if ((optField & OPTIONS::CURR_FILE) == OPTIONS::CURR_FILE)
			std::cout << "Looking into " << files.at(i) << std::endl;
		if ((optField & OPTIONS::CREAT_LOG) == OPTIONS::CREAT_LOG)
            fut = std::async(std::launch::async, &BinFinder::containsInFile, &bf, vecPat, 1, true);     // std::launch::async force async to create a thread
		else
            fut = std::async(std::launch::async, &BinFinder::containsInFile, &bf, vecPat, 1, false);    // std::launch::async force async to create a thread
		offset = fut.get();
		if (offset > -1)
			std::cout << "Found in: " << files.at(i) << " at offset: " << std::hex << "0x" << offset << std::endl;
	}

	if (dtr) delete dtr;
	exit(EXIT_SUCCESS);
}