b_getc: Revert double check on EOB
b_print: add eob check in do/while b_load: use feof() instead of EOF check
This commit is contained in:
parent
c8ed43f82f
commit
c80fb62142
21
buffer.c
21
buffer.c
|
@ -244,7 +244,7 @@ char* b_setmark(Buffer* const pBD, short mark) {
|
||||||
*/
|
*/
|
||||||
int b_eob(Buffer* const pBD) {
|
int b_eob(Buffer* const pBD) {
|
||||||
if (!pBD) { return R_FAIL1; }
|
if (!pBD) { return R_FAIL1; }
|
||||||
return pBD->eob;
|
return (unsigned int) pBD->eob;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adds one character symbol to the character buffer, incrementing its size if
|
/* Adds one character symbol to the character buffer, incrementing its size if
|
||||||
|
@ -353,20 +353,12 @@ char b_getc(Buffer* const pBD) {
|
||||||
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 {
|
}
|
||||||
|
|
||||||
pBD->eob = UNSET_EOB_FLAG;
|
pBD->eob = UNSET_EOB_FLAG;
|
||||||
}
|
|
||||||
/* Fetch character at read offset if EOB check passed */
|
/* Fetch character at read offset if EOB check passed */
|
||||||
char_buf = pBD->cb_head[pBD->getc_offset++];
|
return 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) {
|
|
||||||
pBD->eob = SET_EOB_FLAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
return char_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prints the output of the buffer
|
/* Prints the output of the buffer
|
||||||
|
@ -394,9 +386,9 @@ int b_print(Buffer* const pBD) {
|
||||||
/* Save getc_offset to restore after printing */
|
/* Save getc_offset to restore after printing */
|
||||||
tmp_offset = pBD->getc_offset;
|
tmp_offset = pBD->getc_offset;
|
||||||
pBD->getc_offset = OFFSET_RESET;
|
pBD->getc_offset = OFFSET_RESET;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char_buf = b_getc(pBD);
|
char_buf = b_getc(pBD);
|
||||||
|
if (b_eob(pBD)) { break; }
|
||||||
printf("%c", (char) char_buf);
|
printf("%c", (char) char_buf);
|
||||||
char_count++;
|
char_count++;
|
||||||
} while (!b_eob(pBD));
|
} while (!b_eob(pBD));
|
||||||
|
@ -414,6 +406,7 @@ int b_print(Buffer* const pBD) {
|
||||||
* Parameters:
|
* Parameters:
|
||||||
- FILE* const fi
|
- FILE* const fi
|
||||||
- pBuffer const pBD
|
- pBuffer const pBD
|
||||||
|
* Return value: int, -1
|
||||||
* Return value: int, -1 (R_FAIL1), -2 (LOAD_FAIL)
|
* Return value: int, -1 (R_FAIL1), -2 (LOAD_FAIL)
|
||||||
*/
|
*/
|
||||||
int b_load(FILE* const fi, Buffer* const pBD) {
|
int b_load(FILE* const fi, Buffer* const pBD) {
|
||||||
|
@ -427,7 +420,7 @@ 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*/
|
/* Check loaded character if it's at the end*/
|
||||||
if (char_buf == EOF) {
|
if (feof(fi)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Stop loading if adding a character fails */
|
/* Stop loading if adding a character fails */
|
||||||
|
|
Loading…
Reference in New Issue