-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsaudade.c
More file actions
84 lines (79 loc) · 2.01 KB
/
saudade.c
File metadata and controls
84 lines (79 loc) · 2.01 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
#include "shell.h"
/**
* cleanData - initializes info_t struct
* @data: struct address
*/
void cleanData(info_t *data)
{
/* Set the 'arg' member of 'data' to NULL */
data->arg = NULL;
/* Set the 'argv' member of 'data' to NULL */
data->argv = NULL;
/* Set the 'path' member of 'data' to NULL */
data->path = NULL;
/* Set the 'argc' member of 'data' to 0 */
data->argc = 0;
}
/**
* fixData - initializes info_t struct
* @data: struct address
* @av: argument vector
*/
void fixData(info_t *data, char **av)
{
int a = 0;
/* Set the 'fname' component of 'data' to the 'av's first element */
data->fname = av[0];
/* Verify that the 'arg' member of the 'data' is not NULL */
if (data->arg)
{
/* arg divided into an array of strings using spaces & tabs as delimiters */
data->argv = strSplit(data->arg, " \t");
/* Check if 'argv' is still NULL after splitting 'arg' */
if (!data->argv)
{
data->argv = malloc(sizeof(char *) * 2);
if (data->argv)
{
data->argv[0] = _strdupsd(data->arg);
data->argv[1] = NULL; /* Set the second element of 'argv' to NULL */
}
}
for (a = 0; data->argv && data->argv[a]; a++)
;
data->argc = a;
substituteAlias(data); /* Replace aliases where necessary */
substituteVar(data); /* Substitute variables as necessary */
}
}
/**
* freeData - frees info_t struct fields
* @data: struct address
* @all: true if freeing all fields
*/
void freeData(info_t *data, int all)
{
freeStringArray(data->argv);
data->argv = NULL;
data->path = NULL;
/* Make sure the 'all' argument is true */
if (all)
{
if (!data->cmd_buf)
free(data->arg);
if (data->env)
freeList(&(data->env));
if (data->history)
freeList(&(data->history));
if (data->alias)
freeList(&(data->alias));
freeStringArray(data->environ);
data->environ = NULL;
beFreed((void **)data->cmd_buf);
/* Check if 'readingFd' member of 'data' is greater than 2 and */
/* close the file descriptor */
if (data->readingFd > 2)
close(data->readingFd);
_putchar(BUFFER_FLUSHER);
}
}