buffer.c/.h: Documentation
This commit is contained in:
parent
11614dac4f
commit
bb95cac9ee
21
buffer.c
21
buffer.c
|
@ -7,10 +7,9 @@
|
||||||
* Professor: Svillen Ranev
|
* Professor: Svillen Ranev
|
||||||
* A character buffer utility with three modes of self-incrementation
|
* A character buffer utility with three modes of self-incrementation
|
||||||
through dynamic memory allocation, and ability to set a mark flag.
|
through dynamic memory allocation, and ability to set a mark flag.
|
||||||
* Function list: b_create, b_addc, b_reset, b_free, b_isfull,
|
* Function list: b_create, b_isfull, b_isempty, b_size, b_capacity,
|
||||||
* b_size, b_capacity, b_setmark, b_mark, b_mode, b_incfactor,
|
b_mode, b_incfactor, b_mark, b_flag, b_getcoffset, b_cbhead, b_setmark,
|
||||||
* b_load, b_isempty, b_eob, b_getc, b_print, b_pack, b_rflag,
|
b_eob, b_addc, b_getc, b_print, b_load, b_reset, b_retract, b_pack, b_free
|
||||||
b_retract, b_retract_to_mark, b_getcoffset, b_cbhead
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,7 +219,8 @@ char* b_cbhead(Buffer* const pBD) {
|
||||||
return pBD->cb_head;
|
return pBD->cb_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets a mark offset on the buffer's mark flag
|
/* Sets a mark offset on the buffer's mark flag and returns a pointer
|
||||||
|
to cb_head at that offset
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Version: 0.0.1
|
* Version: 0.0.1
|
||||||
* Called functions: N/A
|
* Called functions: N/A
|
||||||
|
@ -349,16 +349,19 @@ char b_getc(Buffer* const pBD) {
|
||||||
char char_buf;
|
char char_buf;
|
||||||
|
|
||||||
if (!pBD) { return R_FAIL2; }
|
if (!pBD) { return R_FAIL2; }
|
||||||
|
/* Make sure the buffer isn't at the end of the read offset*/
|
||||||
if (pBD->getc_offset == pBD->addc_offset) {
|
if (pBD->getc_offset == pBD->addc_offset) {
|
||||||
pBD->eob = SET_EOB_FLAG;
|
pBD->eob = SET_EOB_FLAG;
|
||||||
return R_FAIL1;
|
return R_FAIL1;
|
||||||
} else {
|
} else {
|
||||||
pBD->eob = UNSET_EOB_FLAG;
|
pBD->eob = UNSET_EOB_FLAG;
|
||||||
}
|
}
|
||||||
|
/* Fetch character at read offset if EOB check passed */
|
||||||
char_buf = pBD->cb_head[pBD->getc_offset++];
|
char_buf = pBD->cb_head[pBD->getc_offset++];
|
||||||
|
|
||||||
|
/* Double check if it is at EOB and set flag if needed.
|
||||||
|
Standard behaviour for a buffer/file stream
|
||||||
|
*/
|
||||||
if (pBD->getc_offset == pBD->addc_offset) {
|
if (pBD->getc_offset == pBD->addc_offset) {
|
||||||
pBD->eob = SET_EOB_FLAG;
|
pBD->eob = SET_EOB_FLAG;
|
||||||
}
|
}
|
||||||
|
@ -423,11 +426,11 @@ int b_load(FILE* const fi, Buffer* const pBD) {
|
||||||
|
|
||||||
while (!feof(fi)) {
|
while (!feof(fi)) {
|
||||||
char_buf = (char) fgetc(fi);
|
char_buf = (char) fgetc(fi);
|
||||||
|
/* Check loaded character if it's at the end*/
|
||||||
if (char_buf == EOF) {
|
if (char_buf == EOF) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* Stop loading if adding a character fails */
|
||||||
if (!b_addc(pBD, char_buf)) {
|
if (!b_addc(pBD, char_buf)) {
|
||||||
return LOAD_FAIL;
|
return LOAD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
9
buffer.h
9
buffer.h
|
@ -2,8 +2,13 @@
|
||||||
* Version: 1.16.2
|
* Version: 1.16.2
|
||||||
* Author: S^R & Victor Fernandes
|
* Author: S^R & Victor Fernandes
|
||||||
* Date: 1 February 2017
|
* Date: 1 February 2017
|
||||||
* Preprocessor directives, type declarations and prototypes necessary for buffer implementation
|
* Preprocessor directives, type declarations and prototypes
|
||||||
|
necessary for buffer implementation
|
||||||
* as required for CST8152, Assignment #1, Winter 2017.
|
* as required for CST8152, Assignment #1, Winter 2017.
|
||||||
|
* Function list: b_create, b_addc, b_reset, b_free, b_isfull,
|
||||||
|
b_size, b_capacity, b_setmark, b_mark, b_mode, b_incfactor,
|
||||||
|
b_load, b_isempty, b_eob, b_getc, b_print, b_pack, b_rflag,
|
||||||
|
b_retract, b_retract_to_mark, b_getcoffset, b_cbhead
|
||||||
*/
|
*/
|
||||||
#ifndef BUFFER_H_
|
#ifndef BUFFER_H_
|
||||||
#define BUFFER_H_
|
#define BUFFER_H_
|
||||||
|
@ -14,7 +19,7 @@
|
||||||
|
|
||||||
/* standard header files */
|
/* standard header files */
|
||||||
#include <stdio.h> /* standard input/output */
|
#include <stdio.h> /* standard input/output */
|
||||||
#include <mm_malloc.h> /* for dynamic memory allocation. NOTE: USE MALLOC.H FOR LINUX/WINDOWS.THIS IS FOR MACOS ONLY*/
|
#include <malloc.h> /* for dynamic memory allocation.*/
|
||||||
#include <limits.h> /* implementation-defined data type ranges and limits */
|
#include <limits.h> /* implementation-defined data type ranges and limits */
|
||||||
|
|
||||||
/* constant definitions */
|
/* constant definitions */
|
||||||
|
|
Loading…
Reference in New Issue