Exemplo n.º 1
0
int main()
{
	unit_test::timeout();

	all_complete();
	all_partial();
	return fail;
}
int reverse_file(char* file_path, int simul_count){

	int i = 0;

	FILE *fp = fopen(file_path, "r");
	char* line = 0;
	StrWordRev* lines[simul_count];

	size_t len = 0;
	ssize_t read;

	while(1){
		// Get `simul_count` number of strings from files, turning them into SWR structs.
		for (i = 0; i < simul_count; ++i){
			read = getline(&line, &len, fp);
			if (read == -1){
				fclose(fp);
				return 1;
			}
			remove_newline(line);
			lines[i] = new_swr(line);
			free(line);
			line = 0;
		}
		while (!all_complete(lines, simul_count)){
			// Move the cursor to the "top" of the block
			for (i = 0; i < simul_count; ++i){
				printf("\033[1A");
				printf("\033[1A");
				printf("\r");
			}
			// Conduct a single "tick" of the reversal of each string
			for (i = 0; i < simul_count; ++i){
				if (lines[i]->state != COMPLETE){
					tick_reverse_word(lines[i]);
				}
				// Print each string with it's fancy highlighting
				rev_debug_print(lines[i]->raw_str, lines[i]->a, lines[i]->b);
			}
			usleep(50000);
		}
		for (i = 0; i < simul_count; ++i){
			rev_debug_print(lines[i]->raw_str, lines[i]->a, lines[i]->b);
		}
	}
	fclose(fp);
	return 0;
}