/* getop.c */

#include <stdio.h>
#include <ctype.h>
#include "getch.h"
#include "getop.h"

int getop(char s[])
{
	int i, c;
	while((s[0] = c = getch()) == ' ' || c == '\t') { ; }
	s[1] = '\0';

	/* case of an operator symbol: +, *, ... */
	if(!isdigit(c) && c != '.') {
		return(c);
	}
	
	/* check if the current input token is a number, possibly with '.' ... */
	i = 0;
	if(isdigit(c)) {
		while(isdigit(s[++i] = c = getch())) { ; }
	}
	if(c == '.') {
		while(isdigit(s[++i] = c = getch())) { ; }
	}
	s[i] = '\0';

	/* we have consumed one extra character, so return it to the buffer */
	if(c != EOF) {
		ungetch(c);
	}

	return(NUM);
}

