-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss-manage_info.c
69 lines (68 loc) · 1.28 KB
/
ss-manage_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
#include "shell.h"
/**
* clear_info - initializes info_s struct
* @info: struct address
*/
void clear_info(info_s *info)
{
info->arg = NULL;
info->argv = NULL;
info->path = NULL;
info->argc = 0;
}
/**
* set_info - initializes info_s struct
* @info: struct address
* @av: argument vector
*/
void set_info(info_s *info, char **av)
{
int i = 0;
info->prog_name = 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 (i = 0; info->argv && info->argv[i]; i++)
;
info->argc = i;
change_alias(info);
change_v(info);
}
}
/**
* free_info - frees info_s struct fields
* @info: struct address
* @all: true if freeing all fields
*/
void free_info(info_s *info, int all)
{
free_vector(info->argv);
info->argv = NULL;
info->path = NULL;
if (all)
{
if (!info->sep_buff)
free(info->arg);
if (info->env)
free_list(&(info->env));
if (info->history)
free_list(&(info->history));
if (info->alias)
free_list(&(info->alias));
free_vector(info->environ);
info->environ = NULL;
bfree((void **)info->sep_buff);
if (info->fd_read > 2)
close(info->fd_read);
_putchar(NEG_ONE);
}
}