-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetopcode.c
More file actions
59 lines (54 loc) · 1020 Bytes
/
getopcode.c
File metadata and controls
59 lines (54 loc) · 1020 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "monty.h"
/**
* get_opcode - Check if opc is a opcode.
* @opc: Command to check.
* Return: a function-potiner to execute de opcode, NULL on failure.
*/
void (*get_opcode(char *opc))(stack_t **, unsigned int)
{
instruction_t command[] = {
{"push", push},
{"pall", pall},
{"pint", pint},
{"pop", pop},
{"swap", swap},
{"add", add},
{"nop", nop},
{"sub", sub},
{"div", _div},
{"mul", _mul},
{"mod", _mod},
{"pchar", pchar},
{"pstr", pstr},
{"rotl", rotl},
{"rotr", rotr},
{"stack", _stack},
{"queue", _queue},
{NULL, NULL}};
int cont = 0;
while (command[cont].opcode)
{
if (strcmp(opc, command[cont].opcode) == 0)
return (*(command[cont].f));
cont++;
}
return (NULL);
}
/**
* check_comment - Checks if the line contains the # to reemplace for '\0'
* @line: Line read by getline to check
* Return: void
*/
void check_comment(char *line)
{
int i = 0;
while (*(line + i))
{
if (*(line + i) == 35)
{
*(line + i) = '\0';
break;
}
i++;
}
}