diff --git a/ass1e.pls b/ass1e.pls new file mode 100755 index 0000000..e69de29 diff --git a/ass1fi_test.out b/ass1fi_test.out new file mode 100644 index 0000000..cdcb22d --- /dev/null +++ b/ass1fi_test.out @@ -0,0 +1,33 @@ +Reading file ass1.pls ....Please wait +The input file ass1.pls is not completely loaded. +Input file size: 327 + +Printing buffer parameters: + +The capacity of the buffer is: 200 +The current size of the buffer is: 200 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙ + +Printing buffer parameters: + +The capacity of the buffer is: 201 +The current size of the buffer is: 201 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙˙ diff --git a/buffer.c b/buffer.c index faf86e4..ccf6526 100644 --- a/buffer.c +++ b/buffer.c @@ -270,35 +270,33 @@ Buffer* b_addc(Buffer* const pBD, char symbol) { return NULL; } + /* Reset reallocation flag */ pBD->r_flag = UNSET_R_FLAG; - /* BEGIN BUFFER INCREASE */ + + /* BEGIN BUFFER INCREMENT */ if (pBD->addc_offset == pBD->capacity){ - if (pBD->mode == FIX_OP_MODE) { /* Fixed mode */ + if (pBD->mode == FIX_OP_MODE) { /* Fixed mode, won't increment */ return NULL; } else if (pBD->mode == ADD_OP_MODE) { /* Calculate new size for additive mode */ - new_cap = pBD->capacity + (unsigned char) pBD->inc_factor; - - /* Maximum additive increment is 255, therefore, if the current - capacity happens to be SHRT_MAX - 1, the value will underflow to a negative number - every time, and never "wrap" to a value greater than 1. - */ + new_cap = pBD->capacity + pBD->inc_factor; + /* Make sure no short overflow happened */ if (new_cap < MIN_CAPACITY){ return NULL; } + } else if (pBD->mode == MUL_OP_MODE) { /* Calculate new size in multiplicative mode */ - if (pBD->capacity == SHRT_MAX){ + if (pBD->capacity == SHRT_MAX){ /* Do nothing if at maximum size */ return NULL; } - /* Mathematically, new_inc cannot be negative, since avail_space will - always be greater or equal to 0. - */ avail_space = SHRT_MAX - pBD->capacity; new_inc = (avail_space * (unsigned char) pBD->inc_factor / 100); - /* The same situation in Additive mode (L284) applies to Multiplicative Mode */ - if (new_inc <= MIN_CAPACITY && pBD->capacity < SHRT_MAX) { + + /* Check if there is enough space for the new increment and + "trim" it if needed */ + if (new_inc >= avail_space) { new_cap = SHRT_MAX; } else { @@ -307,11 +305,13 @@ Buffer* b_addc(Buffer* const pBD, char symbol) { } /* Reallocate memory to character buffer */ - old_addr = pBD->cb_head; /* Keep track of old pointer address for checking if it changed */ + old_addr = pBD->cb_head; /* Keep track of old pointer address to check if it changed */ tmp_addr = (char *)realloc(pBD->cb_head, sizeof(char) * new_cap); + if (tmp_addr == NULL){ return NULL; /* Abort everything if allocation fails */ } + pBD->cb_head = tmp_addr; pBD->capacity = new_cap; if (old_addr == pBD->cb_head) { /* Compare the old and new addresses and set flag appropriately */ @@ -363,16 +363,6 @@ int b_print(Buffer* const pBD) { if (b_isempty(pBD) == TRUE) { printf("The Buffer is empty.\n"); } else { pBD->getc_offset = OFFSET_RESET; - /* Trick the buffer into resetting the eob while printing the contents. - * The EOB flag will be set again once the loop is finished. - * - char_buf = b_getc(pBD); - b_retract(pBD); - for (char_count = 0; b_eob(pBD) == FALSE; char_count++) { - char_buf = b_getc(pBD); - printf("%c", (char) char_buf); - } - printf("\n");*/ do { char_buf = b_getc(pBD); printf("%c", (char) char_buf); @@ -397,36 +387,24 @@ int b_print(Buffer* const pBD) { int b_load(FILE* const fi, Buffer* const pBD) { char char_buf; /* "Buffer" character to be loaded before adding to cb_head */ int char_count = 0; /* Character counter */ - /*char eof_flag;*/ - if (!fi || !pBD) { return LOAD_FAIL; } -/* - for (char_count = 0; !feof(fi); char_count++) { - char_buf = (char) fgetc(fi); - if (char_buf == EOF) { break; } + if (!fi || !pBD) { + return LOAD_FAIL; + } - if (!b_addc(pBD, char_buf)) { return LOAD_FAIL; } - }*/ do { char_buf = (char) fgetc(fi); - if (char_buf == EOF) { break; } - - if (!b_addc(pBD, char_buf)) { return LOAD_FAIL; } - char_count++; - } while (!feof(fi)); - /*eof_flag = feof(fi); - for (char_count = 0; !eof_flag; char_count++) { - char_buf = (char) fgetc(fi); - eof_flag = feof(fi); - - if (char_buf == EOF) { + if (char_buf == (char) EOF) { break; } - if (b_addc(pBD, char_buf) == NULL) { + if (!b_addc(pBD, char_buf)) { return LOAD_FAIL; } - }*/ + + char_count++; + } while (!feof(fi)); + return char_count; } diff --git a/buffer.h b/buffer.h index bbf2aee..4a5bb39 100755 --- a/buffer.h +++ b/buffer.h @@ -14,7 +14,7 @@ /* standard header files */ #include /* standard input/output */ -#include /* for dynamic memory allocation*/ +#include /* for dynamic memory allocation*/ #include /* implementation-defined data type ranges and limits */ /* constant definitions */ @@ -30,7 +30,7 @@ #define R_FAIL2 -2 /* fail return value */ #define LOAD_FAIL -2 /* load fail error */ #define SET_R_FLAG 1 /* realloc flag set value */ -#define UNSET_R_FLAG 0 /* unset realloc flag */ +#define UNSET_R_FLAG 0 /* unset reallocation flag */ #define SET_EOB_FLAG 1 /* set end of buffer flag */ #define UNSET_EOB_FLAG 0 /* unset end of buffer flag */ diff --git a/buffer.h.gch b/buffer.h.gch index cf12a75..e312475 100644 Binary files a/buffer.h.gch and b/buffer.h.gch differ diff --git a/platy b/platy index e926d1c..452cfb8 100755 Binary files a/platy and b/platy differ diff --git a/platy_bt.c b/platy_bt.c index 3f8faf4..ecc1d60 100755 --- a/platy_bt.c +++ b/platy_bt.c @@ -1,8 +1,8 @@ /* File name: platy_bt.c - * Purpose:This is the main program for Assignment #1, CST8152, Fall 16 - * Version: 1.16.2 + * Purpose:This is the main program for Assignment #1, CST8152, Winter 17 + * Version: 1.17.1 * Author: Svillen Ranev - * Date: 6 September 2016 + * Date: 9 January 2017 */ /* The #define _CRT_SECURE_NO_WARNINGS should be used in MS Visual Studio projects diff --git a/platy_gnu b/platy_gnu new file mode 100755 index 0000000..59a334b Binary files /dev/null and b/platy_gnu differ diff --git a/a.out b/platy_llvm similarity index 67% rename from a.out rename to platy_llvm index 4f58b00..8560caa 100755 Binary files a/a.out and b/platy_llvm differ diff --git a/test.out b/test.out new file mode 100644 index 0000000..cdcb22d --- /dev/null +++ b/test.out @@ -0,0 +1,33 @@ +Reading file ass1.pls ....Please wait +The input file ass1.pls is not completely loaded. +Input file size: 327 + +Printing buffer parameters: + +The capacity of the buffer is: 200 +The current size of the buffer is: 200 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙ + +Printing buffer parameters: + +The capacity of the buffer is: 201 +The current size of the buffer is: 201 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙˙ diff --git a/test/ass1ai_test.out b/test/ass1ai_test.out new file mode 100644 index 0000000..a3e5a23 --- /dev/null +++ b/test/ass1ai_test.out @@ -0,0 +1,41 @@ +Reading file ass1.pls ....Please wait + +Printing buffer parameters: + +The capacity of the buffer is: 335 +The current size of the buffer is: 327 +The operational mode of the buffer is: 1 +The increment factor of the buffer is: 15 +The current mark of the buffer is: 327 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all computer users to +ignore the machine-dependent details of machine language. +Isn't that nice? =:) + +CST8152 +Autumn, 2016˙ + +Printing buffer parameters: + +The capacity of the buffer is: 328 +The current size of the buffer is: 328 +The operational mode of the buffer is: 1 +The increment factor of the buffer is: 15 +The current mark of the buffer is: 327 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all computer users to +ignore the machine-dependent details of machine language. +Isn't that nice? =:) + +CST8152 +Autumn, 2016˙˙ diff --git a/test/ass1fi_test.out b/test/ass1fi_test.out new file mode 100644 index 0000000..cdcb22d --- /dev/null +++ b/test/ass1fi_test.out @@ -0,0 +1,33 @@ +Reading file ass1.pls ....Please wait +The input file ass1.pls is not completely loaded. +Input file size: 327 + +Printing buffer parameters: + +The capacity of the buffer is: 200 +The current size of the buffer is: 200 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙ + +Printing buffer parameters: + +The capacity of the buffer is: 201 +The current size of the buffer is: 201 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙˙ diff --git a/test/ass1mi_test.out b/test/ass1mi_test.out new file mode 100644 index 0000000..110b8a9 --- /dev/null +++ b/test/ass1mi_test.out @@ -0,0 +1,41 @@ +Reading file ass1.pls ....Please wait + +Printing buffer parameters: + +The capacity of the buffer is: 5085 +The current size of the buffer is: 327 +The operational mode of the buffer is: -1 +The increment factor of the buffer is: 15 +The current mark of the buffer is: 327 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all computer users to +ignore the machine-dependent details of machine language. +Isn't that nice? =:) + +CST8152 +Autumn, 2016˙ + +Printing buffer parameters: + +The capacity of the buffer is: 328 +The current size of the buffer is: 328 +The operational mode of the buffer is: -1 +The increment factor of the buffer is: 15 +The current mark of the buffer is: 327 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all computer users to +ignore the machine-dependent details of machine language. +Isn't that nice? =:) + +CST8152 +Autumn, 2016˙˙ diff --git a/test_gnu.out b/test_gnu.out new file mode 100644 index 0000000..cdcb22d --- /dev/null +++ b/test_gnu.out @@ -0,0 +1,33 @@ +Reading file ass1.pls ....Please wait +The input file ass1.pls is not completely loaded. +Input file size: 327 + +Printing buffer parameters: + +The capacity of the buffer is: 200 +The current size of the buffer is: 200 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙ + +Printing buffer parameters: + +The capacity of the buffer is: 201 +The current size of the buffer is: 201 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙˙ diff --git a/test_llvm.out b/test_llvm.out new file mode 100644 index 0000000..cdcb22d --- /dev/null +++ b/test_llvm.out @@ -0,0 +1,33 @@ +Reading file ass1.pls ....Please wait +The input file ass1.pls is not completely loaded. +Input file size: 327 + +Printing buffer parameters: + +The capacity of the buffer is: 200 +The current size of the buffer is: 200 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙ + +Printing buffer parameters: + +The capacity of the buffer is: 201 +The current size of the buffer is: 201 +The operational mode of the buffer is: 0 +The increment factor of the buffer is: 0 +The current mark of the buffer is: 200 + +Printing buffer contents: + +Compilers are fundamental to modern computing. +They act as translators, transforming human-oriented +language into computer-oriented machine-language. +A compiler allows virtually all co˙˙