-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_func.c
37 lines (35 loc) · 681 Bytes
/
get_func.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
#include "monty.h"
/**
* get_func -returns the propper func depending on the opcode
*
* @opcode: tells the function to be called
*
* Return: void
*/
void (*get_func(char *opcode))(stack_t **, unsigned int)
{
instruction_t inst[] = {
{"push", _push}, {"pall", _pall},
{"pint", _pint}, {"pop", _pop},
{"swap", _swap}, {"add", _add},
{"sub", _sub}, {"nop", _empty},
{"div", _div}, {"mul", _mul},
{"mod", _mod}, {"pchar", _pchar},
{"empty", _empty},
{NULL, NULL}
};
int i = 0;
while (inst[i].opcode)
{
if (opcode[0] == '#')
{
return (_empty);
}
if (strcmp(opcode, inst[i].opcode) == 0)
{
return (inst[i].f);
}
i++;
}
return (NULL);
}