int main (int argc, char **argv) { if (argc != 1) { fprintf (stderr, "Usage: %s\n", basename (argv[0])); fflush (NULL); exit (EXIT_FAILURE); } stack the_stack; the_stack.top = EMPTY; char buffer[1024]; for (;;) { int scanrc = scanf ("%1023s", buffer); if (scanrc == EOF) break; assert (scanrc == 1); if (buffer[0] == '#') { scanrc = scanf ("%1023[^\n]", buffer); continue; } char *endptr; double number = strtod (buffer, &endptr); if (*endptr == '\0') { push (&the_stack, number); }else if (buffer[1] != '\0') { bad_operator (buffer); }else { do_operator (&the_stack, buffer); } } return exit_status; }
void do_operator (stack *the_stack, const char *oper) { switch (oper[0]) { case '+': do_binop (the_stack, '+'); break; case '-': do_binop (the_stack, '-'); break; case '*': do_binop (the_stack, '*'); break; case '/': do_binop (the_stack, '/'); break; case ';': do_print (the_stack); break; case '@': do_clear (the_stack); break; default : bad_operator (oper); break; } }
void do_operator (stack *the_stack, const char *oper) { switch (*oper) { case '+': do_binop (the_stack, '+'); break; case '-': do_binop (the_stack, '-'); break; case '*': do_binop (the_stack, '*'); break; case '/': do_binop (the_stack, '/'); break; case ';': do_print (the_stack); break; case '@': do_clear (the_stack); break; default : bad_operator (oper); break; } //printf ("the_stack=%p, top=%d, oper=\"%s\"\n", // the_stack, the_stack->top, oper); }