-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_args.c
More file actions
45 lines (41 loc) · 802 Bytes
/
handle_args.c
File metadata and controls
45 lines (41 loc) · 802 Bytes
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
#include "main.h"
/**
* handle_arguments - handle command arguments
* @arg: arguments
* Return: a string
*/
char *handle_arguments(char *arg)
{
char *str = arg;
int status;
pid_t pid = getpid();
if (arg == NULL)
return (NULL);
if (_strchr(arg, '"') != NULL)
{
/*printf("thing found\n");*/
str = delete_char(arg, '"');
}
if (_strcmp(arg, "$?") == 0)
{
return (WIFEXITED(status) ? "1" : "0");
}
else if (_strcmp(arg, "$$") == 0)
{
str = int_to_string(pid);
}
else if (arg[0] == '$')
{
/*printf("a $ thing found\n");*/
arg = delete_char(arg, '$');
str = _getenv(arg);
/*printf("here it is: %s \n", str);*/
}
else if (strchr(arg, '$'))
{
str = _strtok(arg, "$");
_strcat(str, _getenv(_strtok(NULL, "$")));
}
/*printf("nothing found\n");*/
return (str);
}