-
Notifications
You must be signed in to change notification settings - Fork 0
/
linked.c
99 lines (92 loc) · 2.5 KB
/
linked.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* linked.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/03 12:13:32 by zwalad #+# #+# */
/* Updated: 2022/08/25 18:30:32 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int struct_init(t_list *p)
{
p->line2 = readline("➜ minishell ");
if (p->line2 && p->line2[0] != 0)
add_history(p->line2);
p->error = 0;
p->errorx = 0;
p->ext = 0;
if (p->line2 == NULL)
p->ext = 1;
if (p->line2 == NULL || check_piipe(p))
return (0);
p->line = pr_strdup("");
p = dollar_init(p);
free(p->line2);
p = qts_check(p);
if (p->ext != 1 && p->errorx != 1 && p->error != 1)
{
p->wn = pr_wnb2(p->line, ' ') + 1;
p->m = malloc(sizeof(t_mini));
p = struct_beta(p);
}
return (0);
}
t_list *struct_beta(t_list *p)
{
p->m->ii = 0;
p->m->oo = 0;
p->m->hr = 0;
p->m->op = 0;
p->m->open = malloc(sizeof(char *) * p->wn);
p->m->ouf = malloc(sizeof(char *) * p->wn);
p->m->inf = malloc(sizeof(char *) * p->wn);
p->m->her = malloc(sizeof(char *) * p->wn);
p->m->val = malloc(sizeof(char *) * p->wn);
p->m->otype = malloc(sizeof(int) * p->wn);
p->m->j = 0;
p->m->next = NULL;
p->i = 0;
p->on = 0;
return (p);
}
t_mini *new_node(t_list *p)
{
t_mini *m;
m = malloc(sizeof(t_mini));
m->ouf = malloc(sizeof(char *) * p->wn);
m->open = malloc(sizeof(char *) * p->wn);
m->inf = malloc(sizeof(char *) * p->wn);
m->her = malloc(sizeof(char *) * p->wn);
m->val = malloc(sizeof(char *) * p->wn);
m->otype = malloc(sizeof(int) * p->wn);
m->ii = 0;
m->hr = 0;
m->oo = 0;
m->op = 0;
m->j = 0;
p->m->j = 0;
m->next = NULL;
return (m);
}
t_mini *goto_last(t_mini *m)
{
if (!m)
return (0);
while (m->next != NULL)
m = m->next;
return (m);
}
t_mini *addlast_node(t_mini **m, t_mini *new)
{
if (*m == NULL)
*m = new;
else
{
*m = goto_last(*m);
(*m)->next = new;
}
return (*m);
}