-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetops.c
49 lines (45 loc) · 858 Bytes
/
getops.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
#include "monty.h"
/**
* findOps - finds OpCode match and then executes the OpCode.
* @token: token command passed.
* @stk: the stack.
* @line_number: the line number.
*
* Return: void
*/
void findOps(char *token, stack_t **stk, unsigned int line_number)
{
int a = 0;
instruction_t op[] = {
{"push", push},
{"pall", pall},
{"pint", pint},
{"pop", pop},
{"swap", swap},
{"add", add},
{"sub", sub},
{"div", _div},
{"mul", _mul},
{"nop", _nop},
{"pchar", pchar},
{"pstr", pstr},
{"mod", _mod},
{"rotl", rotl},
{"rotr", rotr},
{NULL, NULL}
};
while (op[a].opcode != NULL)
{
if (strcmp(token, op[a].opcode) == 0)
{
op[a].f(stk, line_number);
return;
}
a++;
}
line_number++;
fprintf(stderr, "L%d: unknown instruction %s\n",
line_number, token);
free_stk(stk, line_number);
exit(EXIT_FAILURE);
}