-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
74 lines (67 loc) · 1.82 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-kham <sel-kham@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/19 17:17:03 by ozahir #+# #+# */
/* Updated: 2022/09/04 01:49:24 by sel-kham ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/headers/minishell.h"
int closing_check(char *str, int *fd)
{
int type;
int i;
int state;
type = 0;
i = 0;
state = 0;
fd[0] = -1;
fd[1] = -1;
while (str[i])
{
if ((str[i] == 39 || str[i] == 34) && state == 0)
{
state = 1;
type = str[i];
i++;
}
if (str[i] == type && state == 1)
state = 0;
i++;
}
if (state)
return (printf("error: unclosed quotes\n"), 1);
return (0);
}
char *get_prompt(void)
{
char *user;
char *prompt;
user = getenv("USER");
if (!user)
prompt = ft_strdup("trial@spaghetti % ");
else
prompt = ft_strjoin(user, "@spaghetti % ");
if (!prompt)
return (NULL);
return (prompt);
}
int main(void)
{
char *prompt;
extern char **environ;
prompt = get_prompt();
init_env();
g_exit_stat[3] = 0;
if (!prompt)
return (printf("failed to set prompt value\n"), 1);
shell(prompt);
ft_putstr_fd("\b\b \b\b", 2);
free(prompt);
clear_history();
free_2d_table(environ);
return (0);
}