예제 #1
0
파일: build_index.c 프로젝트: Zabrane/aino
int main(int argc, char **argv)
{
        u64  total_size = sizeof(struct header_s);
        char *basename  = pparm_common_name("index");
        char *iname     = NULL;
        int  fd         = 0;
        u64  offs       = sizeof(struct header_s);
        uint i;
       
        struct header_s header;
        
        dub_init();
      
        PPARM_INT_D(iblock, IBLOCK);
        PPARM_INT_D(segment_size, SEGMENT_SIZE);

        asprintf(&iname, "%s.%u", basename, iblock);
        
        fill_parameters(&header);
        
        for (i = 0; i < DEX_NOF_SECT; i++){
                header.toc_offs[i] = total_size;
                total_size += append_sect(0, 0, i, 1);
        }
        for (i = 0; i < DEX_NOF_SECT; i++){
                header.data_offs[i] = total_size;
                total_size += append_sect(0, 0, i, 0);
        }

        if ((fd = open(iname, O_CREAT | O_TRUNC | O_RDWR | O_LARGEFILE,
                                        S_IREAD | S_IWRITE)) == -1)
                dub_sysdie("Couldn't open file %s", iname);
        
        if (fio_truncate(fd, total_size))
                dub_sysdie("Couldn't truncate index to %llu bytes",
                                total_size);
        
        write(fd, &header, sizeof(struct header_s));
        
        for (i = 0; i < DEX_NOF_SECT; i++)
                offs += append_sect(fd, offs, i, 1);
        
        for (i = 0; i < DEX_NOF_SECT; i++)
                offs += append_sect(fd, offs, i, 0);

        close(fd);
        
        print_structure(&header);
        printf(" In total %llu bytes.\n\n", total_size);
        
        return 0;
}
int main(int argc, char *argv[]){

	std::vector<std::string> params;
	std::map<std::string, std::vector<std::string>> options;
	std::set<std::string> flags;
	std::set<std::string> option_set = {
		"-i", "--input",
		"-o", "--output"
	};
	std::set<std::string> flag_set = {
		"-h", "--help",
		"--nocolor"
	};

	pinput::parse(argc, argv, params, options, flags, option_set, flag_set);


	const bool nocolor = flags.count("--nocolor");

	const char* ecolor = (nocolor)? "" : ansi::red;
	const char* rcolor = (nocolor)? "" : ansi::reset;

	const bool show_help = flags.count("-h") || flags.count("--help");
	if(show_help){
		help();
		return 0;
	}

	try{
		bool open_in = false, open_out = false;
		std::string file_name_in, file_name_out[3];

		fill_parameters(options, file_name_in, open_in, file_name_out, open_out);
		
		std::vector<double> vector_u;
		std::vector<uint> vector_d;
		std::vector<uint> vector_n;

		size_t u_width;
		size_t d_width;
		size_t n_width;
		size_t k;

		os::benchmark_t benchmark;

		// INPUT
		std::streambuf* buffer_in;
		std::ifstream ifstream;
		if(open_in){
			ifstream.open(file_name_in);
			buffer_in = ifstream.rdbuf();
		}
		else buffer_in = std::cin.rdbuf();
		std::istream istream(buffer_in);

		os::load_benchmark(istream, benchmark, vector_u, vector_d, vector_n, u_width, d_width, n_width, k);
		if(open_in) ifstream.close();

		std::vector<std::vector<double>> mean[3] = {
			std::vector<std::vector<double>>(u_width, std::vector<double>(2,0)),
			std::vector<std::vector<double>>(d_width, std::vector<double>(2,0)),
			std::vector<std::vector<double>>(n_width, std::vector<double>(2,0))
		};

		os::study::gnuplot(benchmark, u_width, d_width, n_width, k, mean);

		// OUTPUT
		std::streambuf* buffer_out[3];
		std::ofstream ofstream[3];
		if(open_out){
			for(size_t i = 0; i < 3; ++i){
				ofstream[i].open(file_name_out[i]);
				buffer_out[i] = ofstream[i].rdbuf();
			}
		}
		else buffer_out[0] = buffer_out[1] = buffer_out[2] = std::cout.rdbuf();
		std::ostream ostream0(buffer_out[0]);
		std::ostream ostream1(buffer_out[1]);
		std::ostream ostream2(buffer_out[2]);

		os::store_gnuplot(ostream0, mean[0], vector_u, u_width);
		os::store_gnuplot(ostream1, mean[1], vector_d, d_width);
		os::store_gnuplot(ostream2, mean[2], vector_n, n_width);

		if(open_out) for(size_t i = 0; i < 3; ++i) ofstream[i].close();
	}
	catch(const std::exception& e){
		std::cout << ecolor << "error -> " << e.what() << rcolor << std::endl;
		return 1;
	}
	return 0;
}
int main(int argc, char *argv[]){
	std::vector<std::string> params;
	std::map<std::string, std::vector<std::string>> options;
	std::set<std::string> flags;
	std::set<std::string> option_set = {
		"-i", "--input",
		"-o", "--output"
	};
	std::set<std::string> flag_set = {
		"-h", "--help",
		"--nocolor"
	};

	pinput::parse(argc, argv, params, options, flags, option_set, flag_set);


	const bool nocolor = flags.count("--nocolor");

	const char* ecolor = (nocolor)? "" : ansi::red;
	const char* rcolor = (nocolor)? "" : ansi::reset;

	const bool show_help = flags.count("-h") || flags.count("--help");
	if(show_help){
		help();
		return 0;
	}

	try{

		bool open_in = false;
		std::string file_name_in;
		std::vector<std::string> file_name_out;

		fill_parameters(options, file_name_in, open_in, file_name_out);
		
		std::vector<double> vector_u;
		std::vector<uint> vector_d;
		std::vector<uint> vector_n;

		size_t u_width;
		size_t d_width;
		size_t n_width;
		size_t k;

		os::benchmark_t benchmark;

		// INPUT
		std::streambuf* buffer_in;
		std::ifstream ifstream;
		if(open_in){
			ifstream.open(file_name_in);
			buffer_in = ifstream.rdbuf();
		}
		else buffer_in = std::cin.rdbuf();
		std::istream istream(buffer_in);

		os::load_benchmark(istream, benchmark, vector_u, vector_d, vector_n, u_width, d_width, n_width, k);
		if(open_in) ifstream.close();

		if(n_width > file_name_out.size()) throw lib::exception("too few output files");

		std::vector<os::benchmark_t> new_benchmark(n_width);

		for(auto& x : benchmark){
			new_benchmark[x.n].push_back(x);
		}

		for(size_t i = 0; i < n_width; ++i){
			std::ofstream ofstream(file_name_out[i]);
			os::store_benchmark(ofstream, new_benchmark[i], vector_u, vector_d, std::vector<uint>(1,vector_n[i]), u_width, d_width, 1, k);
			ofstream.close();
		}

	}
	catch(const std::exception& e){
		std::cout << ecolor << "error -> " << e.what() << rcolor << std::endl;
		return 1;
	}

	return 0;
}