-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaux_error1.c
More file actions
132 lines (128 loc) · 2.95 KB
/
Copy pathaux_error1.c
File metadata and controls
132 lines (128 loc) · 2.95 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "main.h"
/**
* strcat_cd - function that concatenates the message for cd error
*
* @datash: data relevant (directory)
* @msg: message to print
* @error: output message
* @ver_str: counter lines
* Return: error message
*/
char *strcat_cd(data_shell *datash, char *msg, char *error, char *ver_str)
{
char *illegal_flag;
_strcpy(error, datash->av[0]);
_strcat(error, ": ");
_strcat(error, ver_str);
_strcat(error, ": ");
_strcat(error, datash->args[0]);
_strcat(error, msg);
if (datash->args[1][0] == '-')
{
illegal_flag = malloc(3);
illegal_flag[0] = '-';
illegal_flag[1] = datash->args[1][1];
illegal_flag[2] = '\0';
_strcat(error, illegal_flag);
free(illegal_flag);
}
else
{
_strcat(error, datash->args[1]);
}
_strcat(error, "\n");
_strcat(error, "\0");
return (error);
}
/**
* error_get_cd - error message for cd command in get_cd
* @datash: data relevant (directory)
* Return: Error message
*/
char *error_get_cd(data_shell *datash)
{
int length, len_id;
char *error, *ver_str, *msg;
ver_str = aux_itoa(datash->counter);
if (datash->args[1][0] == '-')
{
msg = ": Illegal option ";
len_id = 2;
}
else
{
msg = ": can't cd to ";
len_id = _strlen(datash->args[1]);
}
length = _strlen(datash->av[0]) + _strlen(datash->args[0]);
length += _strlen(ver_str) + _strlen(msg) + len_id + 5;
error = malloc(sizeof(char) * (length + 1));
if (error == 0)
{
free(ver_str);
return (NULL);
}
error = strcat_cd(datash, msg, error, ver_str);
free(ver_str);
return (error);
}
/**
* error_not_found - generic error message for command not found
* @datash: data relevant (counter, arguments)
* Return: Error message
*/
char *error_not_found(data_shell *datash)
{
int length;
char *error;
char *ver_str;
ver_str = aux_itoa(datash->counter);
length = _strlen(datash->av[0]) + _strlen(ver_str);
length += _strlen(datash->args[0]) + 16;
error = malloc(sizeof(char) * (length + 1));
if (error == 0)
{
free(error);
free(ver_str);
return (NULL);
}
_strcpy(error, datash->av[0]);
_strcat(error, ": ");
_strcat(error, ver_str);
_strcat(error, ": ");
_strcat(error, datash->args[0]);
_strcat(error, ": not found\n");
_strcat(error, "\0");
free(ver_str);
return (error);
}
/**
* error_exit_shell - generic error message for exit in get_exit
* @datash: data relevant (counter, arguments)
* Return: Error message
*/
char *error_exit_shell(data_shell *datash)
{
int length;
char *error;
char *ver_str;
ver_str = aux_itoa(datash->counter);
length = _strlen(datash->av[0]) + _strlen(ver_str);
length += _strlen(datash->args[0]) + _strlen(datash->args[1]) + 23;
error = malloc(sizeof(char) * (length + 1));
if (error == 0)
{
free(ver_str);
return (NULL);
}
_strcpy(error, datash->av[0]);
_strcat(error, ": ");
_strcat(error, ver_str);
_strcat(error, ": ");
_strcat(error, datash->args[0]);
_strcat(error, ": Illegal number: ");
_strcat(error, datash->args[1]);
_strcat(error, "\n\0");
free(ver_str);
return (error);
}