-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux_lists.c
executable file
·111 lines (97 loc) · 1.67 KB
/
aux_lists.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "main.h"
/**
* add_sep_node_end - adds a separator found at the end
* of a sep_list.
* @head: head of the linked list.
* @sep: separator found (; | &).
* Return: address of the head.
*/
sep_list *add_sep_node_end(sep_list **head, char sep)
{
sep_list *new, *temp;
new = malloc(sizeof(sep_list));
if (new == NULL)
return (NULL);
new->separator = sep;
new->next = NULL;
temp = *head;
if (temp == NULL)
{
*head = new;
}
else
{
while (temp->next != NULL)
temp = temp->next;
temp->next = new;
}
return (*head);
}
/**
* free_sep_list - frees a sep_list
* @head: head of the linked list.
* Return: no return.
*/
void free_sep_list(sep_list **head)
{
sep_list *temp;
sep_list *curr;
if (head != NULL)
{
curr = *head;
while ((temp = curr) != NULL)
{
curr = curr->next;
free(temp);
}
*head = NULL;
}
}
/**
* add_line_node_end - adds a command line at the end
* of a line_list.
* @head: head of the linked list.
* @line: command line.
* Return: address of the head.
*/
line_list *add_line_node_end(line_list **head, char *line)
{
line_list *new, *temp;
new = malloc(sizeof(line_list));
if (new == NULL)
return (NULL);
new->line = line;
new->next = NULL;
temp = *head;
if (temp == NULL)
{
*head = new;
}
else
{
while (temp->next != NULL)
temp = temp->next;
temp->next = new;
}
return (*head);
}
/**
* free_line_list - frees a line_list
* @head: head of the linked list.
* Return: no return.
*/
void free_line_list(line_list **head)
{
line_list *temp;
line_list *curr;
if (head != NULL)
{
curr = *head;
while ((temp = curr) != NULL)
{
curr = curr->next;
free(temp);
}
*head = NULL;
}
}