-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.c
52 lines (45 loc) · 858 Bytes
/
arguments.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
#include "monty.h"
cmd_t cmd = {NULL, NULL};
/**
*interpretor - reads the file and executes the monty bytecodes
*@argv: argument vector
*/
void interpretor(char *argv)
{
int line = 0, r = 0;
size_t size = 0;
char *token = NULL;
char *val = NULL;
stack_t *stack = NULL;
cmd.fd = fopen(argv, "r");
if (cmd.fd)
{
while (getline(&cmd.line, &size, cmd.fd) != -1)
{
line++;
token = strtok(cmd.line, " \n\t\r");
if (token == NULL)
{
free(token);
continue;
}
else if (*token == '#')
{
continue;
}
val = strtok(NULL, " \n\t\r");
r = get_opc(&stack, token, val, line);
if (r == 1)
push_error(cmd.fd, cmd.line, stack, line);
else if (r == -1)
inst_error(cmd.fd, cmd.line, stack, token, line);
}
free(cmd.line);
free_stack(stack);
fclose(cmd.fd);
}
else
{
open_error(argv);
}
}