-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_commands_util.c
73 lines (65 loc) · 1.23 KB
/
simple_commands_util.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
#include "headers.h"
struct simple_commands *create_new_command()
{
struct simple_commands *node = (struct simple_commands *)malloc(sizeof(struct simple_commands));
return node;
}
void add_new_command(struct simple_commands *node)
{
if (head == NULL && tail == NULL)
{
head = node;
tail = node;
}
else
{
tail->next = node;
tail = node;
}
}
void pop_command()
{
if (head == tail && head == NULL)
{
return;
}
else if (head == tail && head != NULL)
{
struct simple_commands *temp = head;
head = NULL;
tail = NULL;
free(temp);
}
else
{
struct simple_commands *temp = head;
head = head->next;
temp->next = NULL;
free(temp);
}
}
void show_commands()
{
struct simple_commands *p = head;
while (p != NULL)
{
int cnt = p->cnt_args;
for (int i = 0; i < cnt; ++i)
{
printf("%s ", p->cmd[i]);
}
printf("\n");
p = p->next;
}
}
void clear_commands()
{
while (head != NULL)
{
for (int i = 0; i < head->cnt_args; ++i)
{
free(head->cmd[i]);
}
pop_command();
}
}