~rabbits/firth

9aa3260db71f85db8f3a5c6a2ccdcbfa40e5a6e6 — neauoire 2 months ago 6cdb24f master
Replaced string parsing with scanf
1 files changed, 3 insertions(+), 29 deletions(-)

M 1th.c
M 1th.c => 1th.c +3 -29
@@ 35,33 35,6 @@ PrintMode MODE;
/* helpers */

int
cinu(char c)
{
	return c >= '0' && c <= '9';
}

int
sinu(char *s)
{
	int i = 0;
	if(!s[0])
		return 0;
	while(s[i])
		if(!cinu(s[i++]))
			return 0;
	return 1;
}

int
snum(char *s)
{
	int i = 0, n = 0;
	while(s[i] && cinu(s[i]))
		n = n * 10 + (s[i++] - '0');
	return n;
}

int
scmp(char *a, char *b)
{
	int i = 0;


@@ 170,6 143,7 @@ print(Stack *s)
int
interpret(Stack *s, char *word)
{
	int value;
	if(!word[0] || word[0] == ' ' || word[0] == '.')
		print(s);
	else if(scmp(word, "std"))


@@ 182,8 156,8 @@ interpret(Stack *s, char *word)
		MODE = HEXADECIMAL;
	else if(scmp(word, "bin"))
		MODE = BINARY;
	else if(sinu(word) && trypush(s, 1))
		push(s, Frac(snum(word), 1));
	else if(sscanf(word, "%d", &value) && trypush(s, 1))
		push(s, Frac(value, 1));
	/* stack */
	else if(scmp(word, "pop") && trypop(s, 1))
		pop(s);