-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
41 lines (39 loc) · 883 Bytes
/
main.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
#include "monty.h"
global_t var;
/**
* main - interpreter for Monty ByteCodes files
* @argc: Number of paramethers
* @argv: Pointer to all the paramethers
*
* Return: Always 0
*/
int main(int argc, char **argv)
{
size_t line_buf_size = 0;
var.getl_info = NULL;
var.stack_head = NULL;
var.n_lines = 0;
if (argc != 2)
{
fprintf(stderr, "USAGE: monty file\n");
exit(EXIT_FAILURE);
}
var.fp_struct = fopen(argv[1], "r");
if (!var.fp_struct)
{
fprintf(stderr, "Error: Can't open file %s\n", argv[1]);
exit(EXIT_FAILURE);
}
while (getline(&var.getl_info, &line_buf_size, var.fp_struct) != EOF)
{
var.n_lines++;
if (line_validator(var.getl_info) == 1)
continue;
/*split_str(var.getl_info);*/
execute_opcode(split_str(var.getl_info));
}
free(var.getl_info);
handle_dlist_head(var.stack_head);
fclose(var.fp_struct);
return (EXIT_SUCCESS);
}