-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopcode.c
More file actions
44 lines (42 loc) · 733 Bytes
/
opcode.c
File metadata and controls
44 lines (42 loc) · 733 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
37
38
39
40
41
42
43
44
#include "monty.h"
/**
* get_opcode - function that get opcode
* @head: stack head
* @args:arguments
* @val:value to ge
* @line_num: line number
* Return: success or failure
*/
int get_opcode(stack_t **head, char *args, char *val, int line_num)
{
int i = 0;
instruction_t opc[] = {
{"push", push},
{"pall", pall},
{"pint", pint},
{"pop", pop},
{"nop", nop},
{"swap", swap},
{"add", add},
{NULL, NULL}
};
while (opc[i].opcode)
{
if (!strcmp(args, opc[i].opcode))
{
if (!strcmp(args, "push"))
{
if (_isdigit(val) == 1)
vals = atoi(val);
else
return (1);
}
opc[i].f(head, (unsigned int)line_num);
break;
}
i++;
}
if (!opc[i].opcode)
return (-1);
return (0);
}