-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss-manage_builtins_b.c
117 lines (104 loc) · 2.43 KB
/
ss-manage_builtins_b.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
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
#include "shell.h"
/**
* handle_exit - exits the shell
* @info: contains simulated arguments for a function pointer,
* allowing for a consistent function prototype
* Return: exits with a given exit status
* (0) if info.argv[0] != "exit"
*/
int handle_exit(info_s *info)
{
int exitcheck;
if (info->argv[1]) /* If there is an exit arguement */
{
exitcheck = err_num(info->argv[1]);
if (exitcheck == -1)
{
info->status = 2;
print_error(info, "Illegal number: ");
puts_err(info->argv[1]);
putchar_err('\n');
return (1);
}
info->error_code = err_num(info->argv[1]);
return (-2);
}
info->error_code = -1;
return (-2);
}
/**
* handle_cd - changes the current directory of the process
* @info: contains simulated arguments for a function pointer,
* allowing for a consistent function prototype
*
* Return: 0
*/
int handle_cd(info_s *info)
{
char *s, *dir, buffer[1024];
int chdir_ret;
s = getcwd(buffer, 1024);
if (!s)
_puts("TODO: >>getcwd failure emsg here<<\n");
if (!info->argv[1])
{
dir = _getenv(info, "HOME=");
if (!dir)
chdir_ret = /* TODO: what should this be? */
chdir((dir = _getenv(info, "PWD=")) ? dir : "/");
else
chdir_ret = chdir(dir);
}
else if (_strcmp(info->argv[1], "-") == 0)
{
if (!_getenv(info, "OLDPWD="))
{
_puts(s);
_putchar('\n');
return (1);
}
_puts(_getenv(info, "OLDPWD=")), _putchar('\n');
chdir_ret = /* TODO: what should this be? */
chdir((dir = _getenv(info, "OLDPWD=")) ? dir : "/");
}
else
chdir_ret = chdir(info->argv[1]);
if (chdir_ret == -1)
{
print_error(info, "can't cd to ");
puts_err(info->argv[1]), putchar_err('\n');
}
else
{
_setenv(info, "OLDPWD", _getenv(info, "PWD="));
_setenv(info, "PWD", getcwd(buffer, 1024));
}
return (0);
}
/**
* handle_help - prints a message for aa function not implemented
* @info: contains simulated arguments for a function pointer,
* constant function prototype.
* Return: 0
*/
int handle_help(info_s *info)
{
char **arg_array;
arg_array = info->argv;
_puts("help call works. Function not yet implemented \n");
if (0)
_puts(*arg_array);
return (0);
}
/**
* handle_history - displays the history list, one command by line, preceded
* with line numbers, starting at 0.
* @info: contains simulated arguments for a function pointer,
* constant function prototype.
* Return: Always 0
*/
int handle_history(info_s *info)
{
print_list(info->history);
return (0);
}