-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.c
78 lines (68 loc) · 1.42 KB
/
verify.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "monty.h"
arg_t arg = {0, 0};
/**
* comment_check - checks if line is a comment.
* @line - struct containing line content and number.
*
* Return: true if comment otherwise false.
*/
bool comment_check(line_t line)
{
if (!line.content[0])
{
free(line.content);
return (true);
}
if (line.content[0][0] == '#')
{
free(line.content);
return (true);
}
return (false);
}
/**
* argument_check - checks arg validity.
* @token: argument to be checked.
*
* Return: true if valid otherwise false.
*/
bool argument_check(char *token)
{
unsigned int i;
if (!token)
return (false);
for (i = 0; token[i]; i++)
{
if (token[0] == '-')
continue;
if (token[i] < '0' || token[i] > '9')
{
return (false);
}
}
return (true);
}
/**
* push_check - check if push opcode is being used and sets
* global argument variable if true.
* @line: struct containg line content and number.
* @opcode: opcode to compare.
* @meta: struct containing all alocated memory.
*
* Return: NAIN.
*/
void push_check(line_t line, meta_t *meta, char *opcode)
{
if ((strcmp(opcode, "push") == 0) && !argument_check(line.content[1]))
{
free(line.content);
fprintf(stderr, "L%d: usage: push integer\n", line.number);
free(meta->buf);
free_stack(&(meta->stack));
fclose(meta->file);
free(meta);
exit(EXIT_FAILURE);
}
else if (strcmp(opcode, "push") == 0)
arg.arg = atoi(line.content[1]);
}