-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin.c
More file actions
91 lines (82 loc) · 2.1 KB
/
builtin.c
File metadata and controls
91 lines (82 loc) · 2.1 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
#include "main.h"
/**
* shl_exit - exit the current process with a status
* Return: the exit status
*/
int shl_exit(char **argv)
{
(void)(argv);
puts("****************GOODBYE**************\n");
puts("Thanks for using, if encouter any issue or have any feature to add"
"\ncreate a pull request on github or an issue..");
return (0);
}
/**
* clear_all - clears the home screen
* @argv: strings array
* Return: 1
*/
int clear_all(char **argv)
{
(void)(argv);
clear();
return (1);
}
/**
* shl_help - the cli help function
* Return: 0
*/
int shl_help(char **argv)
{
(void)(argv);
puts("***********WELCOME TO AYOBAMI SIMPLE SHELL HELP PAGE***********\n");
puts("Copyright © 2022 Free Software Foundation, Inc.\n");
puts("Supports all Unix shell commands"
"\n Other built in commands are:"
"\npublish: git command to add, commit and publish changes to your github");
return (1);
}
/**
* builtin_call - function that execute the buitin commands
* @argv: data parsed
* @av: array of strings from the command line.
* Return: -1 if function not found, 0 if sucessful,
* 1 if not successful.
*/
int builtin_call(char **argv, char **av)
{
int i;
builtin_t builtin[] = {
{"exit", shl_exit},
{"help", shl_help},
{"cd", shl_cd},
{"1", clear_all},
{"2", games},
{"3", shl_help},
{NULL, NULL}};
/*If the first arg is null prompt again*/
if (argv[0] == NULL)
return (1);
/*Checking if the parsed command is the same with builtin command name*/
for (i = 0; builtin[i].name; i++)
if (strcmp(argv[0], builtin[i].name) == 0)
return (builtin[i].fp(argv));
/*If the command not in buitin run shl_exec on command executable*/
return (shl_exec(argv, av));
}
/**
* shl_cd - changes the dir from the cl
* @argv: string arrays
* Return: 1
*/
int shl_cd(char **argv)
{
if (argv[1] == NULL)
fprintf(stderr, "shl: too few arguments \"cd\"\n");
else
{
if (chdir(argv[1]) != 0)
perror("shl:");
}
return (1);
}