Exemplo n.º 1
0
/**
 * Reset test set (parameter -z)
 */
int
ZapTcase(int argc, char *argv[])
{
	if (carrega_arquivo_tcase(&testSet, workingDir, testSessionName) == ERRO) {
		return ERRO;
	}

	if (delete_io(&testSet) == ERRO) {
		msg("Error deleteting I/O registers");
		return ERRO;
	}
	descarrega_arquivo_tcase(&testSet);
}
Exemplo n.º 2
0
void dynamic_inflate(reader_t *reader)
{
	size_t hlit = read_HLIT(reader) + 257;
	size_t hdist = read_HDIST(reader) + 1;
	size_t hclen = read_HCLEN(reader) + 4;

	/*printf("hclen = %d, hlit = %d, hdist = %d\n", hclen, hlit, hdist);*/

	huffman_code litlen_codes[hlit];
	huffman_code offset_codes[hdist];
	read_alphabets(reader, 
				   litlen_codes, hlit, 
				   offset_codes, hdist, 
				   hclen);

	io *io_s;
	init_io(&io_s);
	byte bytes[LEN_MAX];
	size_t litlen;
	bool is_end_of_block = false;
	size_t block_size = 0;
	while (!is_end_of_block) {
		litlen = read_next_huffman_code(reader, litlen_codes, hlit);
		block_size++;
		if (litlen < END_OF_BLOCK)
			write_byte(io_s, litlen);
		else if (litlen == END_OF_BLOCK)
			is_end_of_block = true;
		else {
			two_bytes length = decode_length(reader, litlen);
			two_bytes offcode = read_next_huffman_code(reader, 
													   offset_codes, 
													   hdist);
		    two_bytes distance = decode_distance(reader, offcode);
			get_cyclic_queue(io_s->output, bytes, length, distance);
			write_bytes(io_s, bytes, length);
			block_size = block_size - 1 + length;
		}
	}
	/*printf("block_size = %d\n", block_size);*/

	write_to_output(io_s, reader->output);
	delete_io(&io_s);
}
void nocompress_inflate(reader_t *reader)
{
	io *io_s;
	init_io(&io_s);

	ignore_byte(reader);
	two_bytes block_size = read_LEN_and_NLEN(reader);

	io_s->block_size = block_size;
	io_s->input = reader->input;
	io_s->output_file = reader->output;

	unget_last_byte(reader);
	write_data(io_s);

	io_s->input = NULL;
	io_s->output_file = NULL;
	delete_io(&io_s);
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	get_args(argc, argv);
	get_files_name();
	
	do_tests();

	FILE *output = fopen(global_args.output_name, "w");
	if (output == NULL)
		die(NULL);

	struct stat input_stat;
	stat(global_args.input_name, &input_stat);
	size_t st_size = input_stat.st_size;

	if (global_args.isdecompress) {
		reader_t *reader;
		init_reader(&reader);
		inflate(reader);
		delete_reader(&reader);
	} else {
		int rc1, rc2;
		pthread_t thread_static, thread_dynamic;

		size_t last_size, size = 0;
		size_t size_static, size_dynamic;

		io *io_static, *io_dynamic, *io_nocom;
		init_io(&io_static);
		init_io(&io_dynamic);
		init_io(&io_nocom);
		io_nocom->output_file = output;

		int k = 1;
		while (size < st_size) {
			printf("k = %d\n", k++);
			if (st_size - size >= BLOCK_SIZE) {
				last_size = BLOCK_SIZE;
			} else {
				last_size = st_size - size;
				io_static->isfinal = true;
				io_dynamic->isfinal = true;
				io_nocom->isfinal = true;
			}

			io_static->offset = size;
			io_static->block_size = last_size;
			io_dynamic->offset = size;
			io_dynamic->block_size = last_size;
			io_nocom->offset = size;
			io_nocom->block_size = last_size;

			rc1 = pthread_create(&thread_static, NULL, 
								 &static_deflate, io_static);
			rc2 = pthread_create(&thread_dynamic, NULL, 
								 &dynamic_deflate, io_dynamic);

			if (rc1 || rc2)
				die("thread creation failed");
			pthread_join(thread_static, NULL);
			pthread_join(thread_dynamic, NULL);
			size_static = io_static->result;
			size_dynamic = io_dynamic->result;

			printf("ss = %d, sd = %d, sn = %d\n", size_static, size_dynamic, last_size);

			if (size_dynamic <= size_static && 
				size_dynamic < last_size) {
				write_to_output(io_dynamic, output);
				copy_last_byte(io_static, io_dynamic);
				copy_last_byte(io_nocom, io_dynamic);
				size += io_dynamic->block_size;
				printf("block_size = %d, size = %d\n", io_dynamic->block_size, size);
			} else if (size_static <= size_dynamic && 
					   size_static < last_size) {
				write_to_output(io_static, output);
				copy_last_byte(io_dynamic, io_static);
				copy_last_byte(io_nocom, io_static);
				size += io_static->block_size;
				printf("block_size = %d, size = %d\n", io_static->block_size, size);
			} else {
				nocompress_deflate(io_nocom);
				copy_last_byte(io_static, io_nocom);
				copy_last_byte(io_dynamic, io_nocom);
				size += io_nocom->block_size;
				printf("block_size = %d, size = %d\n", io_nocom->block_size, size);
			}
		}

		delete_io(&io_static);
		delete_io(&io_dynamic);
		delete_io(&io_nocom);
	}

	free(global_args.output_name);
	fclose(output);
	exit(0);
}