#include <ansi_parms.h>
#include <ewl_misra_types.h>
#include <stdio_api.h>
#include <string.h>

int_t _EWL_CDECL __StringRead(void * isc, int_t ch, int_t Action)
{
	char_t	RetVal;

	__InStrCtrl * Iscp = (__InStrCtrl*)isc;
	switch(Action)
	{
		case __GetAChar:
			RetVal = *(Iscp->NextChar);
			if (RetVal == '\0') {
				Iscp->NullCharDetected = 1;
				MISRA_EXCEPTION_RULE_14_7()
				return EOF;
			} else {
				Iscp->NextChar++;
				MISRA_EXCEPTION_RULE_14_7()
				return (int_t)(uchar_t)RetVal;
			}

		case __UngetAChar:
			if (!Iscp->NullCharDetected) {
				Iscp->NextChar--;
			} else {
				Iscp->NullCharDetected = 0;
			}
			MISRA_EXCEPTION_RULE_14_7()
			return ch;

		case __TestForError:
			MISRA_EXCEPTION_RULE_14_7()
			return Iscp->NullCharDetected;

		default:
			MISRA_EXCEPTION_RULE_14_7()
			return 0;
	}
}
