-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.c
More file actions
48 lines (42 loc) · 894 Bytes
/
exec.c
File metadata and controls
48 lines (42 loc) · 894 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
#include "monty.h"
montyCmd_t montyCmd = {NULL, NULL};
/**
*exec_instr - reads the file and executes the monty byte instruction
*@arg: arguments
*/
void exec_instr(char *arg)
{
int c = 0, rd = 0;
size_t bufsize = 0;
char *token = NULL, *val = NULL;
stack_t *head = NULL;
montyCmd.file = fopen(arg, "r");
if (montyCmd.file)
{
while (getline(&montyCmd.line, &bufsize, montyCmd.file) != -1)
{
c++;
token = strtok(montyCmd.line, " \n\t\r");
if (token == NULL)
{
free(token);
continue;
}
else if (*token == '#')
continue;
val = strtok(NULL, " \n\t\r");
rd = get_opcode(&head, token, val, c);
if (rd == 1)
p_err(montyCmd.file, montyCmd.line, head, c);
else if (rd == -1)
inst_err(montyCmd.file, montyCmd.line, head, token, c);
}
free(montyCmd.line);
free_stack(head);
fclose(montyCmd.file);
}
else
{
o_err(arg);
}
}