/* * Runs the given brainfuck file. * * @param file The brainfuck file to run. * @return EXIT_SUCCESS if no errors are encountered, otherwise EXIT_FAILURE. */ int run_file(FILE *file) { BrainfuckState *state = brainfuck_state(); BrainfuckExecutionContext *context = brainfuck_context(BRAINFUCK_TAPE_SIZE); if (file == NULL) { brainfuck_destroy_context(context); brainfuck_destroy_state(state); return EXIT_FAILURE; } brainfuck_add(state, brainfuck_parse_stream(file)); brainfuck_execute(state->root, context); brainfuck_destroy_context(context); brainfuck_destroy_state(state); fclose(file); return EXIT_SUCCESS; }
/* * Run the given brainfuck string. * * @param code The brainfuck string to run. * @return EXIT_SUCCESS if no errors are encountered, otherwise EXIT_FAILURE. */ int run_string(char *code) { BrainfuckState *state = brainfuck_state(); BrainfuckExecutionContext *context = brainfuck_context(BRAINFUCK_TAPE_SIZE); BrainfuckInstruction *instruction = brainfuck_parse_string(code); brainfuck_add(state, instruction); brainfuck_execute(state->root, context); brainfuck_destroy_context(context); brainfuck_destroy_state(state); return EXIT_SUCCESS; }