-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_info.c
74 lines (68 loc) · 1.31 KB
/
get_info.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
#include "shell.h"
/**
* clear_info - function that initializes info_t struct
* @info: the struct address
*/
void clear_info(info_t *info)
{
info->arg = NULL;
info->argv = NULL;
info->path = NULL;
info->argc = 0;
}
/**
* set_info - function thata initializes info_t struct
* @info: is the struct address
* @av: the argument vector
*/
void set_info(info_t *info, char **av)
{
int j = 0;
info->fname = av[0];
if (info->arg)
{
info->argv = strtow(info->arg, " \t");
if (!info->argv)
{
info->argv = malloc(sizeof(char *) * 2);
if (info->argv)
{
info->argv[0] = _strdup(info->arg);
info->argv[1] = NULL;
}
}
for (j = 0; info->argv && info->argv[j]; j++)
;
info->argc = j;
replace_alias(info);
replace_vars(info);
}
}
/**
* free_info - function that frees info_t struct
* @info: is struct address
* @al: true if freeing all
*/
void free_info(info_t *info, int al)
{
ffree(info->argv);
info->argv = NULL;
info->path = NULL;
if (al)
{
if (!info->cmd_buf)
free(info->arg);
if (info->env)
free_list(&(info->env));
if (info->history)
free_list(&(info->history));
if (info->alias)
free_list(&(info->alias));
ffree(info->environ);
info->environ = NULL;
bfree((void **)info->cmd_buf);
if (info->readfd > 2)
close(info->readfd);
_putchar(BUF_FLUSH);
}
}