#include #include #include "calc.h" extern int getch(); extern void ungetch(int c); /* getop: get next operator or numeric operand */ int getop( char s[] ) { int i, c; int istime=0; int numdot=0; while ((s[0] = c = getch()) == ' ' || c == '\t') ; s[1] = '\0'; if (!isdigit(c) && c != '.' && c != '-') return c; /* not a number */ i = 0; if (c == '-') { if (isdigit(c = getch())) { s[0]='-'; s[1]=c; s[2]='\0'; i++; } else { if (c != EOF) ungetch(c); return '-'; /* not a number */ } } if (isdigit(c)) /* collect integer part */ while (isdigit(s[++i] = c = getch()) || c == '.' || c == ':') { if (c==':') istime=1; if (c=='.') numdot++; } s[i] = '\0'; if (c != EOF) ungetch(c); if (istime != 0) return TIME; if (numdot > 1) return ERROR; return NUMBER; } int sgetop(char s[]) { int i, c; int istime=0; int numdot=0; c=s[0]; if (!isdigit(c) && c != '.' && c != '-') return c; /* not a number */ if (!isdigit(s[1]) && c == '-') return c; /* not a number */ i = 0; if (isdigit(c)) /* collect integer part */ while (isdigit(c=s[++i]) || c == '.' || c == ':') { if (c==':') istime=1; if (c=='.') numdot++; } if (istime != 0) return TIME; if (numdot > 1) return ERROR; return NUMBER; }