-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorList.c
More file actions
113 lines (110 loc) · 2.36 KB
/
Copy pathErrorList.c
File metadata and controls
113 lines (110 loc) · 2.36 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "monty.h"
/**
* Error - Prints error messages indexed by error code.
* @ErrorCode: Error codes are the following cases:
* (1) --> user doesn't give any file or more than one file to the program.
* (2) --> File can't be opened or read.
* (3) --> File contains an invalid instruction.
* (4) --> Program is unable to malloc more memory.
* (5) --> Parameter passed to the instruction "push" is not an int.
* (6) --> Stack is empty for pint.
* (7) --> Stack is empty for pop.
* (8) --> Stack is too short for operation.
*/
void Error(int ErrorCode, ...)
{
va_list AG;
char *op;
int l_num;
va_start(AG, ErrorCode);
switch (ErrorCode)
{
case 1:
fprintf(stderr, "USAGE: monty file\n");
break;
case 2:
fprintf(stderr, "Error: Can't open file %s\n",
va_arg(AG, char *));
break;
case 3:
l_num = va_arg(AG, int);
op = va_arg(AG, char *);
fprintf(stderr, "L%d: unknown instruction %s\n", l_num, op);
break;
case 4:
fprintf(stderr, "Error: malloc failed\n");
break;
case 5:
fprintf(stderr, "L%d: usAGe: push integer\n", va_arg(AG, int));
break;
default:
break;
}
FreeNodes();
exit(EXIT_FAILURE);
}
/**
* MoreError - handles more errors.
* @ErrorCode: Error codes are the following cases:
* (6) --> Stack is empty for pint.
* (7) --> Stack is empty for pop.
* (8) --> Stack is too short for operation.
* (9) --> Divided by zero.
*/
void MoreError(int ErrorCode, ...)
{
va_list AG;
char *op;
int l_num;
va_start(AG, ErrorCode);
switch (ErrorCode)
{
case 6:
fprintf(stderr, "L%d: can't pint, stack empty\n",
va_arg(AG, int));
break;
case 7:
fprintf(stderr, "L%d: can't pop an empty stack\n",
va_arg(AG, int));
break;
case 8:
l_num = va_arg(AG, unsigned int);
op = va_arg(AG, char *);
fprintf(stderr, "L%d: can't %s, stack too short\n", l_num, op);
break;
case 9:
fprintf(stderr, "L%d: division by zero\n",
va_arg(AG, unsigned int));
break;
default:
break;
}
FreeNodes();
exit(EXIT_FAILURE);
}
/**
* StringError - for handling string errors.
* @ErrorCode: Error codes for the following cases:
* (10) --> Number inside the node is outside ASCII bounds.
* (11) --> Stack is empty.
*/
void StringError(int ErrorCode, ...)
{
va_list AG;
int l_num;
va_start(AG, ErrorCode);
l_num = va_arg(AG, int);
switch (ErrorCode)
{
case 10:
fprintf(stderr, "L%d: can't pchar, value out of range\n", l_num);
break;
case 11:
fprintf(stderr, "L%d: can't pchar, stack empty\n", l_num);
break;
default:
break;
}
FreeNodes();
exit(EXIT_FAILURE);
}