void InitializeTestInstructions(Test** tests, const char* test_specification_file_name) { TextFileReader Reader = CreateTextFileReader(test_specification_file_name); if ( Reader.IsInitialized == FALSE ) { printf("Failed to create the Text File Reader"); exit(1); } NumberOfTests = CalculateNumberOfTest(&Reader); *tests = (Test*) malloc( NumberOfTests* sizeof(Test)); shared_result = (Result*)malloc( NumberOfTests* sizeof(Result)); if (*tests == NULL || shared_result == NULL) { printf("Failed to allocate memory for InitializeTestInstructions function \n"); exit(1); } FillTestsFromSpecifications(tests,&Reader); DeleteTextFileReader(Reader); }
int main(int argc, char *argv[]) { char *input_file = NULL; char *output_file = NULL; int initial_direction = 0; int initial_depth = 0; int initial_ammo = 0; Submarine *submarine = NULL; //$// AlreadySeenFriends **already_seen_friends = NULL; AlreadySeenFriends *already_seen_friends = NULL; TextFileReader reader; SubmarineOutputWriter *output_writer = NULL; BOOL simulation_result = FALSE; ErrorCode error_code = SUCCESS; if (!HandleParameters( argc, argv, &input_file, &output_file, &initial_direction, &initial_depth, &initial_ammo )) { LOG_ERROR("Failed to parse the cmd parameters"); error_code = WRONG_PARAMETERS; goto cleanup; }; LOG_INFO("Started Submarine Run with the following parameters: \r\n \ Input File = %s \r\n \ Initial Direction = %d \r\n \ Initial Depth = %d \r\n \ Initial Ammo = %d \r\n \ Output File = %s", input_file, initial_direction, initial_depth, initial_ammo, output_file ); // Create the input file reader reader = CreateTextFileReader(input_file); if (reader.IsInitialized == FALSE) { LOG_ERROR("Failed to initialize the Text Reader"); error_code = TEXT_READER_INITIALIZATION_FAILED; goto cleanup; } // Create the output file writer output_writer = InitializeSubmarineOutputWriter(output_file); if (output_writer == NULL) { LOG_ERROR("Failed to initialize the Submarine Output Writer"); error_code = SUBMARINE_OUTPUT_WRITER_FAILED; goto cleanup; } //Intialize already seen friends structure already_seen_friends = InitializeAlreadySeenFriends(); // Initialize the Submarine submarine = InitializeSubmarine( initial_depth, initial_direction, initial_ammo, output_writer //$// already_seen_friends..fds ); if (submarine == NULL) { LOG_ERROR("Failed to initialize the submarine"); error_code = SUBMARINE_INITIALIZATION_FAILED; goto cleanup; } simulation_result = RunSimulation(submarine, reader, already_seen_friends); if (!simulation_result) { LOG_ERROR("Failed during the simulation"); error_code = SIMULATION_FAILED; } cleanup: // Cleanup if (submarine != NULL) { //$//FreeSubmarine(submarine,already_seen_friends); FreeSubmarine(submarine); } if (already_seen_friends != NULL) { FreeAlreadySeenFriends(already_seen_friends); } if (output_writer != NULL) { CloseSubmarineOutputWriter(output_writer); } if (reader.IsInitialized != FALSE) { DeleteTextFileReader(reader); } return SUCCESS; }