/*
File name: buffer.h
Compiler: Microsoft Visual Studio 2015
Course: Compilers CST-8152
Lab Section: Lab 011
Assignment 1: The Buffer
Date: September 21st 2017
Professor: Svillen Ranev
Purpose: Declare constants as well as functions to be implemented in buffer.c in order to implement a character buffer
Function list: b_allocate(), b_addc(), b_clear(), b_free(), b_isfull(), b_limit(), b_capacity(), b_mark(), b_mode(), b_incfactor(), b_load(), b_isempty(), b_eob(), b_getc(), b_print(), b_compact(), b_rflag(), b_retract(), b_reset(), b_getcoffset(), b_rewind(), b_location()
*/

#ifndef BUFFER_H
#define BUFFER_H

/*#pragma warning (1:4001) /*to enforce C89 type comments  - to make //comments an warning */

/*#pragma warning (error:4001)*//* to enforce C89 comments - to make // comments an error */

								/*#define DEBUGBUFFER*/

								/* Standard header files*/
#include <stdio.h>  /* Standard input/output*/
#include <malloc.h> /* For dynamic memory allocation*/
#include <limits.h> /* Implementation-defined data type ranges and limits*/

								/* Constant definitions*/
#define RT_FAIL1 -1 /* Fail return value */
#define RT_FAIL2 -2 /* Fail return value */
#define LOAD_FAIL -2 /* Load fail error */
#define SET_R_FLAG 1 /* Used for set realloc flag and set buffer flag */
#define UNSET_R_FLAG 0 /* Used for unset realloc flag and unset buffer flag */
#define RT_FAIL3 256 /* Fail return value */
#define TRUE 1 /* True value */
#define FALSE 0 /* False value */
#define FIXED_VALUE 0 /*Buffer fixed mode integer value*/
#define FIXED_IDENTIFIER 'f' /*Buffer fixed mode integer value*/
#define ADDITIVE_VALUE 1 /* Additive mode int value*/
#define ADDITIVE_IDENTIFIER 'a' /* Additive mode character value*/
#define MULT_VALUE -1 /* Multiplicative mode int value*/
#define MULT_IDENTIFIER 'm' /* Multiplicative mode character value*/
#define MAX_BUFFER SHRT_MAX /* Maximum capacity for the buffer maximum size of short max */
#define MAX_INC_FACTOR 100 /* Maximum inc factor*/
#define MIN_INC_FACTOR 1 /* Minimum inc factor*/
								/* User data type declarations*/
typedef struct BufferDescriptor {
	char *cb_head; /* Pointer to the beginning of character array (character buffer) */
	short capacity; /* Current dynamic memory size (in bytes) allocated to character buffer */
	short addc_offset; /* The offset (in chars) to the add-character location */
	short getc_offset; /* The offset (in chars) to the get-character location */
	short markc_offset; /* The offset (in chars) to the mark location */
	char  inc_factor; /* Character array increment factor */
	char  r_flag; /* Character array reallocation flag */
	char  mode; /* Operational mode indicator*/
	int   eob; /* End-of-buffer reached flag */
} Buffer, *pBuffer;
/*typedef Buffer *pBuffer;*/

/* Function declarations*/
Buffer * b_allocate(short init_cap, char inc_factor, char o_mode);
pBuffer b_addc(pBuffer const pBD, char symbol);
int b_clear(Buffer * const pBD);
void b_free(Buffer * const pBD);
int b_isfull(Buffer * const pBD);
short b_limit(Buffer * const pBD);
short b_capacity(Buffer * const pBD);
short b_mark(Buffer * const pBD, short mark);
int b_mode(Buffer * const pBD);
size_t b_incfactor(Buffer * const pBD);
int b_load(FILE * const fi, Buffer * const pBD);
int b_isempty(Buffer * const pBD);
int b_eob(Buffer * const pBD);
char b_getc(Buffer * const pBD);
int b_print(Buffer * const pBD);
Buffer * b_compact(Buffer * const pBD, char symbol);
char b_rflag(Buffer * const pBD);
short b_retract(Buffer * const pBD);
short b_reset(Buffer * const pBD);
short b_getcoffset(Buffer * const pBD);
int b_rewind(Buffer * const pBD);
char * b_location(Buffer * const pBD, short loc_offset);
#endif
#pragma once
