-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_funcs.c
56 lines (51 loc) · 1.03 KB
/
find_funcs.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
49
50
51
52
53
54
55
56
#include "monty.h"
/**
* findFuncs - find the appropriate function for the given opcode
*
* @opcode: opcode
*
* @value: argument of opcode
*
* @format: storage format. If 0 Nodes will be entered as a stack.
*
* @ln: line number
*
* if 1 nodes will be entered as a queue.
* Return: void
*
*/
void findFuncs(char *opcode, char *value, int ln, int format)
{
int k;
int flag;
instruction_t func_list[] = {
{"push", addnodeTos},
{"pall", pall},
{"pint", printTop},
{"pop", popTop},
{"nop", Nop},
{"swap", swapTop2elem},
{"add", addTOtop},
{"sub", subTotop},
{"div", divNodes},
{"mul", multiply_nodes},
{"mod", rem_nodes},
{"pchar", printAscii},
{"pstr", printString},
{"rotl", rotateFtoBot},
{"rotr", rotLastTop},
{NULL, NULL}
};
if (opcode[0] == '#')
return;
for (flag = 1, k = 0; func_list[k].opcode != NULL; k++)
{
if (strcmp(opcode, func_list[k].opcode) == 0)
{
callfuncs(func_list[k].f, opcode, value, ln, format);
flag = 0;
}
}
if (flag == 1)
error_mesg(3, ln, opcode);
}