-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_op.c
executable file
·50 lines (47 loc) · 898 Bytes
/
list_op.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
#include "monty.h"
/**
* lst_opcode - List opcode
* inst_tble: instructions
* @stack: stack_t
* @strct: strct_t
* @opcode: data line
*/
void lst_opcode(stack_t **stack, char *opcode, strct_t strct)
{
register int i;
char *opc;
instruction_t inst_tble[] = {
/*
*{"push", },
*{"sub", },
*{"div", },
*{"mul", },
*{"mod", },
*{"pchar", },
*{"pstr", },
*{"rotl", },
*{"rotr", },
*/
{"add", add},
{"sub", sub},
{"pint", pint},
{"pop", pop},
{"swap", swap},
{"nop", nop},
{"pall", pall},
{NULL, NULL}
};
opc = strtok(opcode, "\n");
for (i = 0; inst_tble[i].opcode; i++)
if (strcmp(opc, inst_tble[i].opcode) == 0)
{
inst_tble[i].f(stack, strct.line_number);
return;
}
dprintf(STDERR_FILENO, "L%d: ", strct.line_number);
dprintf(STDERR_FILENO, "unknown instruction %s\n", opcode);
fclose(strct.file);
free(strct.line);
free_stck(strct.stack);
exit(EXIT_FAILURE);
}