summaryrefslogtreecommitdiffstats
path: root/src/b_h.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 13:55:08 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 13:55:08 +0200
commit7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016 (patch)
tree5e1baac90873e7cefc1f45ec0cfdcbbe4f695309 /src/b_h.c
parenth still in progress (diff)
download42-minishell-7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016.tar.gz
42-minishell-7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016.tar.bz2
42-minishell-7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016.tar.xz
42-minishell-7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016.tar.zst
42-minishell-7eb6a40ab20a4970822a1d34fbb9a8dbc87cd016.zip
In progress
Diffstat (limited to '')
-rw-r--r--src/b_h.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/b_h.c b/src/b_h.c
index 0e968ff..2c4f7eb 100644
--- a/src/b_h.c
+++ b/src/b_h.c
@@ -20,27 +20,64 @@
#include "s_struct.h"
#include "u_utils.h"
-static void b_print_history(const char arg[], uint64_t max_hist, t_msh *msh)
+static uint64_t b_get_total_hist(t_msh *msh)
{
- char *prev_hist;
+ uint64_t total;
+ char *ptr;
+
+ total = 0;
+ if (msh->prev_hist != NULL)
+ {
+ ptr = msh->prev_hist;
+ while (*ptr != C_NUL)
+ {
+ if (*ptr == C_LF)
+ total += 1;
+ ptr++;
+ }
+ }
+ ptr = msh->curr_hist;
+ while (*ptr != C_NUL)
+ {
+ if (*ptr == C_LF)
+ total += 1;
+ ptr++;
+ }
+ return (total);
+}
+
+static void b_print_history(uint64_t asked, uint64_t total, t_msh *msh)
+{
+ char *hist;
char *tok;
uint32_t i;
- (void)arg;
+ (void)total;
+ (void)asked;
i = 1;
- if (msh->prev_hist != NULL)
+ if (msh->hist != NULL)
{
- if ((prev_hist = ft_strdup(msh->prev_hist)) == NULL)
+ if ((hist = ft_strdup(msh->prev_hist)) == NULL)
return ;
- tok = ft_strtok(prev_hist, "\n");
+ tok = ft_strtok(hist, "\n");
while (tok != NULL)
{
ft_printf("%5u %s\n", i, tok);
i++;
tok = ft_strtok(NULL, "\n");
}
- ft_memdel((void*)&prev_hist);
+ ft_memdel((void*)&hist);
+ }
+ if ((hist = ft_strdup(msh->curr_hist)) == NULL)
+ return ;
+ tok = ft_strtok(hist, "\n");
+ while (tok != NULL)
+ {
+ ft_printf("%5u %s\n", i, tok);
+ i++;
+ tok = ft_strtok(NULL, "\n");
}
+ ft_memdel((void*)&hist);
}
static t_bool b_check_numeric(const char arg[])
@@ -77,7 +114,7 @@ uint8_t b_h(char *args[], t_msh *msh)
}
else
{
- b_print_history(*args, msh);
+ b_print_history(ft_atoi(*args), b_get_total_hist(msh), msh);
}
return (0);
}