From fff1ee59d0569fadf56b1c1bbf9b0425ee92ec9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Sun, 3 May 2020 23:36:24 +0200 Subject: seperated bvr_compose_page and bvr_compose_stream, fixed line comments and variable renames/moves --- src/tape.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/tape.c') diff --git a/src/tape.c b/src/tape.c index 5bbec7d..5c574fb 100644 --- a/src/tape.c +++ b/src/tape.c @@ -92,38 +92,29 @@ int bvr_inline_command_processor(FILE * page_source_file, FILE * output_file, ch copy_buffer[(ftell(page_source_file)% COPY_BUFFER_SIZE)] = fgetc(page_source_file); // remove closing command tag character return what_to_return; } - -int bvr_compose_page(char page_source_file_path[], int this_is_a_top_level_page, char * temp_output_path) { - if(temp_output_path != NULL) { - char * temp_output_filename = randstring(16); - char temp_output_path[80] = "tmp/"; - strcat(temp_output_path, temp_output_filename); - } +int bvr_compose_stream(FILE * page_source_file, FILE * temp_output_file) { char copy_buffer[COPY_BUFFER_SIZE]; - FILE * temp_output_file = fopen_mkdir(temp_output_path, "w"); - FILE * page_source_file = fopen(page_source_file_path, "r"); - - for(int i = 0; i < sizeof(copy_buffer); i++) { // da garbage vrednosti ne bodo slučajno ukazi! --- useless!, todo: delete - copy_buffer[i] = ' '; - } - copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); - if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) { - goto done_reading_write_file; + for(int i = 0; i < sizeof(copy_buffer); i++) { // da garbage vrednosti ne bodo slučajno ukazi! + copy_buffer[i] = '\n'; } + // copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); + // if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) { + // goto done_reading_write_file; + // } while (1) { copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == OPENING_COMMAND_TAG_CHAR_1 && copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == OPENING_COMMAND_TAG_CHAR_2) { if(bvr_inline_command_processor(page_source_file, temp_output_file, copy_buffer) == FAILURE) { - fprintf(temp_output_file, "\nbvr_inline_command_processor returned an error status whilst composing %s\n", page_source_file_path); - fprintf(stderr, "[tape.c] bvr_inline_command_processor returned an error status whilst composing %s\n", page_source_file_path); + fprintf(temp_output_file, "\nbvr_inline_command_processor returned an error status.\n"); + fprintf(stderr, "[tape.c] bvr_inline_command_processor returned an error status.\n"); } copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // remove last > that just wants to be there... OB1 continue; } if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == '\n' && copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == LINE_COMMENT_CHAR) { - copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // idk, OB1 is a bitch - while(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] != '\n') { // idk, OB1 is a bitch + // copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // idk, OB1 is a bitch + while(copy_buffer[(ftell(page_source_file)-0)% COPY_BUFFER_SIZE] != '\n') { // idk, OB1 is a bitch copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // idk, OB1 is a bitch } continue; @@ -141,6 +132,21 @@ int bvr_compose_page(char page_source_file_path[], int this_is_a_top_level_page, } fputc(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE], temp_output_file); } + return SUCCESS; +} + +int bvr_compose_page(char page_source_file_path[], int this_is_a_top_level_page, char * temp_output_path) { + if(temp_output_path != NULL) { + char * temp_output_filename = randstring(16); + char temp_output_path[80] = "tmp/"; + strcat(temp_output_path, temp_output_filename); + } + FILE * temp_output_file = fopen_mkdir(temp_output_path, "w"); + FILE * page_source_file = fopen(page_source_file_path, "r"); + if(bvr_compose_stream(page_source_file, temp_output_file) != SUCCESS) { + fprintf(stderr, "[tape.c] bvr_compose_page: bvr_compose_stream returned a non-successful response whilst composing %s. Nevertheless, we are continuing.\n", + page_source_file_path); + } done_reading_write_file: -- cgit v1.2.3