Beispiel #1
0
int
main(int argc, char **argv)
{
	setlocale(LC_ALL, "");
	program_name = argv[0];

	opt_block_size = get_block_size();

	int c;
	while ((c = getopt(argc, argv, "b:c:")) != -1) {
		switch (c) {
		case 'b':
			if (!parse_arg_block_size(optarg))
				usage();
			break;
		case 'c':
			if (!parse_arg_compression(optarg))
				usage();
			break;
		default:
			usage();
		}
	}

	if (argc - optind < 2)
		usage();
	mtbl_output_fname = argv[argc - 1];

	/* open user dso */
	init_dso();

	/* open merger, writer */
	init_mtbl();

	/* open readers */
	const size_t n_readers = argc - 1 - optind;
	struct mtbl_reader *readers[n_readers];
	for (size_t i = 0; i < n_readers; i++) {
		const char *fname = argv[i + optind];
		fprintf(stderr, "%s: opening input file %s\n", program_name, fname);
		readers[i] = mtbl_reader_init(fname, NULL);
		if (readers[i] == NULL) {
			fprintf(stderr, "Error: mtbl_reader_init() failed.\n\n");
			usage();
		}
		mtbl_merger_add_source(merger, mtbl_reader_source(readers[i]));
	}

	/* do merge */
	my_timespec_get(&start_time);
	merge();

	/* cleanup readers */
	for (size_t i = 0; i < n_readers; i++)
		mtbl_reader_destroy(&readers[i]);

	/* call user cleanup */
	if (user_func_free != NULL)
		user_func_free(user_clos);

	print_stats();

	return (EXIT_SUCCESS);
}
Beispiel #2
0
int main(int argc, char ** argv) {
	FILE *tmp = tmpfile();
	assert(tmp != NULL);

	init_mtbl(dup(fileno(tmp)));

	struct mtbl_reader_options *reader_options = mtbl_reader_options_init();
	assert(reader_options != NULL);

	struct mtbl_reader *reader = mtbl_reader_init_fd(dup(fileno(tmp)), reader_options);
	assert(reader != NULL);

	const struct mtbl_source *source = mtbl_reader_source(reader);
	assert(source != NULL);

	struct mtbl_iter *iter = mtbl_source_iter(source);
	assert(iter != NULL);

	test_iter(iter);
	fprintf(stderr, NAME ": PASS: iter run successful\n");

	mtbl_iter_destroy(&iter);

	struct mtbl_merger_options *merger_options = mtbl_merger_options_init();
	assert(merger_options != NULL);

	mtbl_merger_options_set_merge_func(merger_options, my_merge_func, NULL);

	struct mtbl_merger *merger = mtbl_merger_init(merger_options);
	assert(merger != NULL);

	mtbl_merger_add_source(merger, source);

	const struct mtbl_source *merger_source = mtbl_merger_source(merger);
	assert(merger_source != NULL);

	struct mtbl_iter *merger_iter = mtbl_source_iter(merger_source);
	assert(merger_iter != NULL);

	test_iter(merger_iter);
	fprintf(stderr, NAME ": PASS: merger run 1 successful\n");

	mtbl_iter_destroy(&merger_iter);
	
	FILE *tmp2 = tmpfile();
	assert(tmp != NULL);

	init_mtbl(dup(fileno(tmp2)));

	struct mtbl_reader *reader2 = mtbl_reader_init_fd(dup(fileno(tmp2)), reader_options);
	assert(reader2 != NULL);

	mtbl_merger_add_source(merger, mtbl_reader_source(reader2));

	merger_iter = mtbl_source_iter(merger_source);
	assert(merger_iter != NULL);

	test_iter(merger_iter);
	fprintf(stderr, NAME ": PASS: merger run 2 successful\n");

	mtbl_iter_destroy(&merger_iter);

	mtbl_merger_destroy(&merger);
	mtbl_merger_options_destroy(&merger_options);
	mtbl_reader_destroy(&reader);
	mtbl_reader_destroy(&reader2);
	mtbl_reader_options_destroy(&reader_options);

	fclose(tmp);
	fclose(tmp2);
}