summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/d_define.h21
-rw-r--r--src/m_argv.c4
-rw-r--r--src/m_init.c26
-rw-r--r--src/m_init.h20
-rw-r--r--src/m_loop.c4
-rw-r--r--src/m_prompt.c25
-rw-r--r--src/m_prompt.h5
-rw-r--r--src/s_destroy.c1
-rw-r--r--src/s_init.c2
-rw-r--r--src/s_struct.h2
10 files changed, 92 insertions, 18 deletions
diff --git a/src/d_define.h b/src/d_define.h
index 2f819c9..e682071 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -19,8 +19,23 @@
** ====== CLASSICS ======
*/
-#define FT_PS_ONE "minishell ~> "
#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type"
+
+
+/*
+** ====== PSX ======
+*/
+
+#define FT_DEFAULT_PS_ONE "minishell ~> "
+#define FT_DEFAULT_PS_TWO "> "
+#define FT_DEFAULT_PS_THR "> "
+#define FT_DEFAULT_PS_FOU "> "
+
+/*
+** ====== PSX RICE ======
+*/
+
+#define FT_PROGNAME "minishell"
#define FT_MSH_VERSION "0.1"
/*
@@ -51,7 +66,7 @@
** ====== FILES ======
*/
-#define FT_MINISHELLRC ".minishellrc"
-#define FT_MINISHELL_HISTORY ".minishell_history"
+#define FT_MINISHELLRC ".minishellrc"
+#define FT_DEFAULT_HISTFILE ".minishell_history"
#endif
diff --git a/src/m_argv.c b/src/m_argv.c
index 25b386e..46e2640 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -18,6 +18,7 @@
#include "f_fail.h"
#include "d_define.h"
#include "m_comm.h"
+#include "m_init.h"
#include "m_loop.h"
#include "m_mshrc.h"
#include "s_struct.h"
@@ -31,6 +32,7 @@ uint8_t
if (argc == 1)
{
+ m_init_custom_vars(msh);
msh->ret = m_source_mshrc(msh);
msh->ret = m_loop(STDIN_FILENO, msh);
}
@@ -38,7 +40,7 @@ uint8_t
{
if (*(argv + 2) == NULL)
{
- ft_dprintf(2, "%s: %s: option requires an argument\n",
+ ft_dprintf(STDERR_FILENO, "%s: %s: option requires an argument\n",
msh->shname, FT_OPT_COMMAND);
return (2);
}
diff --git a/src/m_init.c b/src/m_init.c
new file mode 100644
index 0000000..c145063
--- /dev/null
+++ b/src/m_init.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* m_init.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+
+#include "s_struct.h"
+#include "u_vars_next.h"
+
+void
+ m_init_custom_vars(t_msh *msh)
+{
+ u_subst_var_value("$PS1", FT_DEFAULT_PS_ONE, msh);
+ u_subst_var_value("$PS2", FT_DEFAULT_PS_TWO, msh);
+ u_subst_var_value("$PS3", FT_DEFAULT_PS_THR, msh);
+ u_subst_var_value("$PS4", FT_DEFAULT_PS_FOU, msh);
+ u_subst_var_value("$HISTFILE", FT_DEFAULT_HISTFILE, msh);
+}
diff --git a/src/m_init.h b/src/m_init.h
new file mode 100644
index 0000000..358db5d
--- /dev/null
+++ b/src/m_init.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* m_init.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef M_INIT_H
+#define M_INIT_H
+
+#include "s_struct.h"
+
+void m_init_custom_vars(t_msh *msh);
+
+#endif
diff --git a/src/m_loop.c b/src/m_loop.c
index 84efddf..2521204 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -65,7 +65,7 @@ void
while (gnl > 0 && ((!(quote = ft_strrchr(buf, '\"'))) &&
(!(quote = ft_strrchr(buf, '\'')))))
{
- m_cont_prompt();
+ m_prompt_psx(2, msh);
gnl = get_next_line(STDIN_FILENO, &line);
buf = strjoin_m(buf, line, 0);
ft_memdel((void*)&line);
@@ -92,7 +92,7 @@ uint8_t
while (gnl > 0)
{
if (fd == STDIN_FILENO)
- m_prompt(msh);
+ m_prompt_psx(1, msh);
gnl = get_next_line(fd, &line);
if (line[0] != '\0')
{
diff --git a/src/m_prompt.c b/src/m_prompt.c
index 34aae09..3bffffd 100644
--- a/src/m_prompt.c
+++ b/src/m_prompt.c
@@ -11,20 +11,33 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdint.h>
#include <unistd.h>
#include "m_prompt.h"
#include "s_struct.h"
+#include "u_vars.h"
-void
- m_cont_prompt(void)
+static void
+ m_update_psx(uint8_t x, t_msh *msh)
{
- ft_dprintf(STDIN_FILENO, "> ");
- /* TODO :ft_printf("%s", msh->ps_two); */
+ char *var;
+ char psx[5];
+
+ ft_sprintf(psx, "$PS%hhu", x);
+ if ((var = u_get_var_value(psx, msh)) == NULL)
+ {
+ msh->ps[x - 1][0] = '\0';
+ return ;
+ }
+ ft_strlcpy(msh->ps[x - 1], var, ft_strlen(var) + 1);
+ ft_memdel((void*)&var);
}
void
- m_prompt(t_msh *msh)
+ m_prompt_psx(uint8_t x, t_msh *msh)
{
- ft_dprintf(STDIN_FILENO, "%s", msh->ps_one);
+
+ m_update_psx(1, msh);
+ ft_dprintf(STDERR_FILENO, "%s", msh->ps[x - 1]);
}
diff --git a/src/m_prompt.h b/src/m_prompt.h
index 3697fae..8aae6f7 100644
--- a/src/m_prompt.h
+++ b/src/m_prompt.h
@@ -13,9 +13,10 @@
#ifndef M_PROMPT_H
#define M_PROMPT_H
+#include <stdint.h>
+
#include "s_struct.h"
-void m_prompt(t_msh *msh);
-void m_cont_prompt(void);
+void m_prompt_psx(uint8_t x, t_msh *msh);
#endif
diff --git a/src/s_destroy.c b/src/s_destroy.c
index a6f84e3..97a47d8 100644
--- a/src/s_destroy.c
+++ b/src/s_destroy.c
@@ -18,7 +18,6 @@
void
s_destroy(t_msh *msh)
{
- ft_memdel((void*)&msh->ps_one);
ft_memdel((void*)&msh->shname);
ft_memdel((void*)&msh->cwd);
ft_delwords(msh->bu_ref);
diff --git a/src/s_init.c b/src/s_init.c
index 63861e6..7b36653 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -130,8 +130,6 @@ t_msh
if (!(msh = (t_msh*)malloc(sizeof(t_msh))))
return (NULL);
- if (!(msh->ps_one = ft_strdup(FT_PS_ONE)))
- return (NULL);
if (!(msh->shname = ft_strdup(argv[0])))
return (NULL);
/* TODO: shname: care about "./", try with symlinks */
diff --git a/src/s_struct.h b/src/s_struct.h
index f5d2a23..15505d5 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -68,7 +68,7 @@ typedef struct s_line
typedef struct s_msh
{
char **envp;
- char *ps_one;
+ char ps[4][1024];
uint8_t ret;
char *shname;
char **bu_ref;