summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-16 19:52:47 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-16 19:52:47 +0200
commitd64bf8070719f761201501c9453a8e255996cdd4 (patch)
treefe5a58da30e564575dbc542c101b3fd380d56ef3 /src
parentTODO update (diff)
download42-minishell-d64bf8070719f761201501c9453a8e255996cdd4.tar.gz
42-minishell-d64bf8070719f761201501c9453a8e255996cdd4.tar.bz2
42-minishell-d64bf8070719f761201501c9453a8e255996cdd4.tar.xz
42-minishell-d64bf8070719f761201501c9453a8e255996cdd4.tar.zst
42-minishell-d64bf8070719f761201501c9453a8e255996cdd4.zip
In progress
Diffstat (limited to 'src')
-rw-r--r--src/b_h.c63
-rw-r--r--src/b_h.h22
-rw-r--r--src/d_define.h5
-rw-r--r--src/d_enum.h1
-rw-r--r--src/s_struct.h1
5 files changed, 90 insertions, 2 deletions
diff --git a/src/b_h.c b/src/b_h.c
new file mode 100644
index 0000000..c669fa6
--- /dev/null
+++ b/src/b_h.c
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_h.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 <libft.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "d_define.h"
+#include "s_struct.h"
+#include "u_utils.h"
+
+static void b_print_history_number(const char arg[])
+{
+ (void)arg;
+}
+
+static t_bool b_check_numeric(const char arg[])
+{
+ char *ptr;
+
+ ptr = arg;
+ while (*ptr != C_NUL)
+ {
+ if (ft_isdigit(*ptr) == FALSE)
+ {
+ return (FALSE);
+ }
+ ptr++;
+ }
+ return (TRUE);
+}
+
+uint8_t b_h(char *args[], t_msh *msh)
+{
+ const uint64_t argc = u_builtins_get_argc((const char **)args);
+
+ if (argc > 1)
+ {
+ f_fail_too_many_args("h", msh);
+ return (127);
+ }
+ if (argc == 1 && b_check_numeric(*args) == FALSE)
+ {
+ ft_dprintf(STDERR_FILENO,
+ "minishell: history: %s: numeric argument required",
+ *args);
+ return (1);
+ }
+ else
+ {
+ b_print_history(*args);
+ }
+ return (0);
+}
diff --git a/src/b_h.h b/src/b_h.h
new file mode 100644
index 0000000..30a78fd
--- /dev/null
+++ b/src/b_h.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_h.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 B_H_H
+#define B_H_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_h(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/d_define.h b/src/d_define.h
index f5dd32e..674a141 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -19,8 +19,8 @@
** ====== CLASSICS ======
*/
-#define M_BUILTINS_REF "echo:cd:pwd:export:unset:env:exit:type:[:alias"
-#define M_BUILTINS_REF_LEN 48
+#define M_BUILTINS_REF "echo:cd:pwd:export:unset:env:exit:type:[:alias:h"
+#define M_BUILTINS_REF_LEN 49
/*
** ====== PSX ======
@@ -76,6 +76,7 @@
#define C_DOLLAR 0x24
#define C_SQUOTE 0x27
#define C_AMP 0x26
+#define C_PLUS 0x2b
#define C_SEMIC 0x3b
#define C_EQUALS 0x3d
#define C_BACKS 0x5c
diff --git a/src/d_enum.h b/src/d_enum.h
index 69d34c9..636598d 100644
--- a/src/d_enum.h
+++ b/src/d_enum.h
@@ -51,6 +51,7 @@ enum
FT_ID_TYPE,
FT_ID_SQB,
FT_ID_ALIAS,
+ FT_ID_H,
FT_BUILTINS_COUNT
};
diff --git a/src/s_struct.h b/src/s_struct.h
index 871b0f4..31313bf 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -81,6 +81,7 @@ typedef struct s_msh
struct s_lvars *vars;
struct s_lalias *alias;
char **envp;
+ char **prev_hist;
char ps[4][1024];
char env_fork_tmp[128][4096];
char sqb_ref[FT_ID_SQB_COUNT][4];