-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
61 lines (54 loc) · 1.8 KB
/
main.c
File metadata and controls
61 lines (54 loc) · 1.8 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lray <lray@student.42lausanne.ch > +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/06 19:08:50 by lray #+# #+# */
/* Updated: 2023/11/02 15:01:22 by lray ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static t_ctx *app_init(t_ctx *ctx, char **envp);
int g_code;
int main(int argc, char **argv, char **envp)
{
t_ctx *ctx;
(void) argc, (void) argv;
ctx = NULL;
ctx = app_init(ctx, envp);
while (1)
{
ctx_free_line(ctx);
sig_update(SIGMODE_DEFAULT);
ctx->input = prompt_get();
if (ctx->input == NULL)
builtin_exit(NULL, ctx);
else if (ctx->input[0] == '\0')
continue ;
if (lexer(ctx) == 0)
continue ;
if (parser(ctx) == 0)
continue ;
if (expand(ctx) == 0)
continue ;
exec(ctx);
}
return (0);
}
static t_ctx *app_init(t_ctx *ctx, char **envp)
{
int pos;
g_code = 0;
ctx = ctx_init(ctx, envp);
pos = grpvar_has(ctx->grpvar, GRPVAR_GLOBAL, "HOME");
if (pos == -1 || ctx->grpvar->global->array[pos]->value[0] == '\0')
{
ft_puterror("init failed");
builtin_exit(NULL, ctx);
}
builtin_cd(NULL, ctx);
grpvar_add(ctx->grpvar, GRPVAR_GLOBAL, "OLDPWD", NULL);
return (ctx);
}