-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_op.c
48 lines (45 loc) · 916 Bytes
/
get_op.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
43
44
45
46
47
48
#include "monty.h"
/**
* get_op - check op against valid opcodes
* @op: op to check
* @stack: double pointer to the beginnig of the stack
* @line_number: script line number
*
* Return: void
*/
void get_op(char *op, stack_t **stack, unsigned int line_number)
{
size_t i;
instruction_t valid_ops[] = {
{"push", m_push},
{"pall", m_pall},
{"pint", m_pint},
{"pop", m_pop},
{"swap", m_swap},
{"add", m_add},
{"nop", m_nop},
{"sub", m_sub},
{"mul", m_mul},
{"div", m_div},
{"mod", m_mod},
{"rotl", rotl},
{"rotr", rotr},
{"stack", m_stack},
{"queue", m_queue},
{"pchar", m_pchar},
{"pstr", m_pstr},
{NULL, NULL}
};
for (i = 0; valid_ops[i].opcode != NULL; i++)
{
if (strcmp(valid_ops[i].opcode, op) == 0)
{
valid_ops[i].f(stack, line_number);
return;
}
}
dprintf(STDOUT_FILENO,
"L%u: unknown instruction %s\n",
line_number, op);
exit(EXIT_FAILURE);
}