aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/eval.h4
-rw-r--r--src/eval/cmd.c5
-rw-r--r--src/lexer/lexer.c2
-rw-r--r--src/main.c47
-rw-r--r--[-rwxr-xr-x]src/parse/cmd_parse.c0
-rw-r--r--[-rwxr-xr-x]src/parse/parse.c0
-rw-r--r--[-rwxr-xr-x]src/parse/redir_parse.c0
7 files changed, 51 insertions, 7 deletions
diff --git a/include/eval.h b/include/eval.h
index e300644..38671aa 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:30 by charles #+# #+# */
-/* Updated: 2020/06/23 08:33:02 by charles ### ########.fr */
+/* Updated: 2020/07/13 09:54:40 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,6 +42,8 @@ typedef struct
# define FDS_WRITE 1
# define FDS_READ 0
+extern pid_t g_child_pid;
+
/*
** op.c
*/
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index 57f9899..fc73ed0 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,12 +6,14 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/06/23 09:04:38 by charles ### ########.fr */
+/* Updated: 2020/07/13 09:54:12 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "eval.h"
+pid_t g_child_pid = -1;
+
/*
** \brief Wrap a function in a fork
** \param fd_in fork input file descriptor
@@ -39,6 +41,7 @@ int fork_wrap(
exit(EXIT_FAILURE);
exit(status);
}
+ g_child_pid = child_pid;
wait(&child_pid);
close(fds[FDS_WRITE]);
// also read end?
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index dd34654..c5d8d68 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -31,6 +31,8 @@ int check_input(char *input)
int i;
i = 0;
+ /* if (input[i] == '(' || input[i] == ')') */
+ /* return (i + 1); */
if (lexer_sep(input[i]))
{
while(input[i] == input[i + 1])
diff --git a/src/main.c b/src/main.c
index b375c16..259f332 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/06/19 19:12:42 by charles ### ########.fr */
+/* Updated: 2020/07/13 10:35:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,6 +26,37 @@ void token_put(void *v);
void print_level(int level);
void ast_print(int level, t_ast *ast);
+void print_prompt(void)
+{
+ printf("\033[0;32m%s\033[0m$ ", getcwd(NULL, 0));
+ fflush(stdout);
+}
+
+void signal_sigint(int signum)
+{
+ (void)signum;
+ if (g_child_pid != -1)
+ {
+ kill(g_child_pid, SIGINT);
+ ft_putchar('\n');
+ }
+ else
+ {
+ ft_putchar('\n');
+ print_prompt();
+ }
+}
+
+void signal_sigquit(int signum)
+{
+ (void)signum;
+ if (g_child_pid != -1)
+ {
+ kill(g_child_pid, SIGQUIT);
+ ft_putstr("Quit (core dumped)\n");
+ }
+}
+
int main(int argc, char **argv, char **envp)
{
t_path path;
@@ -35,6 +66,9 @@ int main(int argc, char **argv, char **envp)
path = path_update(NULL, env_search(env, "PATH"));
/* printf("%s\n", argv[2]); */
+ signal(SIGINT, signal_sigint);
+ signal(SIGQUIT, signal_sigquit);
+
if (argc == 3 && ft_strcmp(argv[1], "-c") == 0)
{
//printf("%s\n", argv[2]);
@@ -68,10 +102,14 @@ int main(int argc, char **argv, char **envp)
int ret;
char *line;
- printf("> ");
- fflush(stdout);
+ print_prompt();
while ((ret = ft_getline(STDOUT_FILENO, &line)) == FTGL_OK)
{
+ if (*line == '\0')
+ {
+ print_prompt();
+ continue;
+ }
t_ftlst *lex_out = lexer(line);
if (lex_out == NULL)
return (1);
@@ -81,8 +119,7 @@ int main(int argc, char **argv, char **envp)
int fds[2] = {MS_NO_FD, MS_NO_FD};
int eval_out = eval(fds, env, path, parser_out->ast);
(void)eval_out;
- printf("> ");
- fflush(stdout);
+ print_prompt();
}
}
diff --git a/src/parse/cmd_parse.c b/src/parse/cmd_parse.c
index 25802c1..25802c1 100755..100644
--- a/src/parse/cmd_parse.c
+++ b/src/parse/cmd_parse.c
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 740726c..740726c 100755..100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
diff --git a/src/parse/redir_parse.c b/src/parse/redir_parse.c
index 768506e..768506e 100755..100644
--- a/src/parse/redir_parse.c
+++ b/src/parse/redir_parse.c