-
Notifications
You must be signed in to change notification settings - Fork 2
/
error_handl.c
87 lines (84 loc) · 1.59 KB
/
error_handl.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
79
80
81
82
83
84
85
86
87
#include "monty.h"
/**
*erro - prints the associated error message to stderr
* @code: the error code
* Return: void
*/
void erro(int code, ...)
{
va_list param;
int dig;
char *par;
va_start(param, code);
switch (code)
{
case 1:
dprintf(STDERR_FILENO, USAGE);
break;
case 2:
dprintf(STDERR_FILENO, NOACCESS, va_arg(param, char *));
break;
case 3:
dig = va_arg(param, int);
par = va_arg(param, char *);
dprintf(STDERR_FILENO, INVALID, dig, par);
break;
case 4:
dprintf(STDERR_FILENO, MALLOC);
break;
case 5:
dprintf(STDERR_FILENO, PUSH, va_arg(param, int));
break;
case 6:
dprintf(STDERR_FILENO, PINT, va_arg(param, int));
break;
case 7:
dprintf(STDERR_FILENO, POP, va_arg(param, int));
break;
default:
erro_ext(code, va_arg(param, int));
break;
}
va_end(param), exit(EXIT_FAILURE);
}
/**
* erro_ext - extensuion for the erro function
* @code: the error code
* @va_arg: the variable argument
* Return: void
*/
void erro_ext(int code, int va_arg)
{
switch (code)
{
case 8:
dprintf(STDERR_FILENO, SWAP, va_arg);
break;
case 9:
dprintf(STDERR_FILENO, ADD, va_arg);
break;
case 10:
dprintf(STDERR_FILENO, SUB, va_arg);
break;
case 11:
dprintf(STDERR_FILENO, DIV, va_arg);
break;
case 12:
dprintf(STDERR_FILENO, DERR, va_arg);
break;
case 13:
dprintf(STDERR_FILENO, MUL, va_arg);
break;
case 14:
dprintf(STDERR_FILENO, MOD, va_arg);
break;
case 15:
dprintf(STDERR_FILENO, PCHAR, va_arg);
break;
case 16:
dprintf(STDERR_FILENO, RANGE, va_arg);
break;
default:
break;
}
}