-
Notifications
You must be signed in to change notification settings - Fork 0
/
_cmd_type.c
38 lines (35 loc) · 864 Bytes
/
_cmd_type.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
#include "main.h"
/**
* _cmd_type - determines the type of command.
* @cmd: the command to be checked.
*
* Return: an integer value representing the type of command (EXTERNAL_CMD = 1,
* PATH_CMD = 2, INTERNAL_CMD = 3), otherwise the value of (INVALID_CMD = -1).
*/
int _cmd_type(char *cmd)
{
char *path = NULL;
int i;
char *internal_cmd[] = {"exit", "env", "setenv", "unsetenv", "cd",
NULL};
/* Check if the cmd is an internal command */
for (i = 0; internal_cmd[i] != NULL; i++)
{
if (_strcmp(cmd, internal_cmd[i]) == 0)
return (INTERNAL_CMD);
}
/* Check if the cmd is an extaernal command */
for (i = 0; cmd[i] != '\0'; i++)
{
if (cmd[i] == '/')
return (EXTERNAL_CMD);
}
/* Check if the cmd is a path command */
path = _check_path(cmd);
if (path != NULL)
{
free(path);
return (PATH_CMD);
}
return (INVALID_CMD);
}