-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin.c
53 lines (44 loc) · 1.02 KB
/
builtin.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
#include "cell.h"
int cell_exit(char **args) //for exit
{
(void)args;
dbzSpinnerLoading();
exit(EXIT_SUCCESS);
}
int cell_env(char **args) //for env
{
// exter -> this variable exist but it's defined somewhere else!
//Because environ is defined in the C runtime and not directly in your program, you need to declare it as extern to tell the compiler:
//"This variable exists somewhere else, not defined here, but I want to use it.
extern char **environ;
(void)args;
if (!environ)
return (1);
for (int i = 0; environ[i]; i++)
p("%s\n", environ[i]);
return (0);
}
int cell_echo(char **args) //for echo
{
int start = 1;
bool newline = true;
if (!args || !args[0])
return (1);
// Check for the -n option
if (args[1] && !strcmp(args[1], "-n"))
{
newline = false;
start = 2;
}
// Print each argument separated by a space
for (int i = start; args[i]; i++)
{
p("%s", args[i]);
if (args[i + 1])
p(" ");
}
// Print newline if -n option is not present
if (newline)
p("\n");
return (0);
}