forked from KFredlund/monty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_filter.c
42 lines (41 loc) · 767 Bytes
/
op_filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "monty.h"
/**
* getop - function that gets the correct function for operation
* @s: string var
* @count: int count
*
* Return: Never
*/
void (*getop(char *s, unsigned int count))(stack_t **stack, unsigned int l)
{
instruction_t ops[] = {
{"push", op_push},
{"pall", op_pall},
{"pint", op_pint},
{"pop", op_pop},
{"swap", op_swap},
{"add", op_add},
{"nop", op_nop},
{"sub", op_sub},
{"div", op_div},
{"mul", op_mul},
{"mod", op_mod},
{"pchar", op_pchar},
{"pstr", op_pstr},
{NULL, NULL}
};
int i = 0;
if (s && s[0] != '#')
{
while (ops[i].opcode != NULL)
{
if (strcmp(ops[i].opcode, s) == 0)
return (ops[i].f);
i++;
}
handle_error(3, count, s);
return (NULL);
}
else
return (ops[6].f);
}