-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_error.c
More file actions
97 lines (91 loc) · 2.41 KB
/
Copy pathprint_error.c
File metadata and controls
97 lines (91 loc) · 2.41 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
#include "shell.h"
/**
* not_found - write error ("sh: 1: lss: not found")
* @str: user's typed command
* @c_n: nth user's typed command
* @env: bring in environmental variables linked list to write shell name
*/
void not_found(char *str, int c_n, list_t *env)
{
int count = 0;
char *shell, *num;
shell = get_env("_", env); /* get shell name to write */
while (shell[count] != '\0')
count++;
write(STDOUT_FILENO, shell, count);
free(shell);
write(STDOUT_FILENO, ": ", 2);
num = int_to_string(c_n); /* convert cmd line num to string to write */
count = 0;
while (num[count] != '\0')
count++;
write(STDOUT_FILENO, num, count);
free(num);
write(STDOUT_FILENO, ": ", 2);
count = 0;
while (str[count] != '\0')
count++;
write(STDOUT_FILENO, str, count);
write(STDOUT_FILENO, ": ", 2);
write(STDOUT_FILENO, "not found\n", 10);
}
/**
* cant_cd_to - write error ("sh: 2: cd: can't cd to xyz")
* @str: user's typed argument after the cmd cd
* @c_n: nth user's typed command
* @env: bring in environmental variables linked list to write shell name
*/
void cant_cd_to(char *str, int c_n, list_t *env)
{
int count = 0;
char *shell, *num;
shell = get_env("_", env);
while (shell[count] != '\0')
count++;
write(STDOUT_FILENO, shell, count);
free(shell);
write(STDOUT_FILENO, ": ", 2);
num = int_to_string(c_n);
count = 0;
while (num[count] != '\0')
count++;
write(STDOUT_FILENO, num, count);
free(num);
write(STDOUT_FILENO, ": ", 2);
write(STDOUT_FILENO, "cd: can't cd to ", 16);
count = 0;
while (str[count] != '\0')
count++;
write(STDOUT_FILENO, str, count);
write(STDOUT_FILENO, "\n", 1);
}
/**
* illegal_number - write error ("sh: 3: exit: Illegal number abc (or -1)")
* @str: user's typed argument after the cmd exit
* @c_n: nth user's typed command
* @env: bring in environmental variables linked list to write shell name
*/
void illegal_number(char *str, int c_n, list_t *env)
{
int count = 0;
char *shell = NULL, *num = NULL;
shell = get_env("_", env);
while (shell[count] != '\0')
count++;
write(STDOUT_FILENO, shell, count);
free(shell);
write(STDOUT_FILENO, ": ", 2);
num = int_to_string(c_n);
count = 0;
while (num[count] != '\0')
count++;
write(STDOUT_FILENO, num, count);
free(num);
write(STDOUT_FILENO, ": ", 2);
write(STDOUT_FILENO, "exit: Illegal number: ", 22);
count = 0;
while (str[count] != '\0')
count++;
write(STDOUT_FILENO, str, count);
write(STDOUT_FILENO, "\n", 1);
}