-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch.c
46 lines (44 loc) · 1.01 KB
/
match.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
#include "monty.h"
#include <string.h>
/**
* match_opcode_instruction - get the function associated with an opcode
* @opcode: the opcode to match
*
* Return: If opcode is NULL, return NULL. If match is found, return the
* corresponding function. If match is not found, exit with EXIT_FAILURE.
*/
instruction_fn match_opcode_instruction(const char *opcode)
{
static instruction_t instructions[] = {
{"add", op_add},
{"div", op_div},
{"mod", op_mod},
{"mul", op_mul},
{"nop", op_nop},
{"pall", op_pall},
{"pchar", op_pchar},
{"pint", op_pint},
{"pop", op_pop},
{"pstr", op_pstr},
{"push", op_push},
{"queue", op_queue},
{"rotl", rot_upward},
{"rotr", rot_downward},
{"stack", op_stack},
{"sub", op_sub},
{"swap", op_swap},
{0}
};
instruction_t *op = instructions;
if (opcode)
{
while (op->opcode)
{
if (!strcmp(opcode, op->opcode))
return (op->fn);
++op;
}
print_err("L%u: unknown instruction %s\n", op_env.lineno, opcode);
}
return (NULL);
}