-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_func.c
More file actions
36 lines (33 loc) · 697 Bytes
/
Copy pathget_func.c
File metadata and controls
36 lines (33 loc) · 697 Bytes
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
#include "monty.h"
/**
* get_func - gets the function
* @cmd: command
* Return: pointer to function
*/
void (*get_func(char *cmd))(stack_t **, unsigned int)
{
instruction_t ops[] = {
{"push", push}, {"queue", queue},
{"pall", pall}, {"rotr", rotr},
{"pint", pint}, {"pchar", pchar},
{"pop", pop}, {"mod", mod},
{"swap", swap}, {"mul", mul},
{"add", add}, {"div", div_2},
{"nop", nop}, {"sub", sub},
{"pstr", pstr}, {"rotl", rotl},
{"stack", stack}, {NULL, NULL}
};
int i = 0;
if (myglob.mode == 1)
{
ops[0].opcode = "push";
ops[0].f = enqueue;
}
while (ops[i].opcode)
{
if (strcmp(cmd, ops[i].opcode) == 0)
return (ops[i].f);
i++;
}
return (NULL);
}