Преглед изворни кода

update history return fn

master
Simon CHAKOR пре 2 година
родитељ
комит
2ae25e980b
  1. 4
      src/history.h
  2. 36
      src/history/rl_line_to_hist.c
  3. 5
      src/readline/return_fn.c

4
src/history.h

@ -70,8 +70,6 @@ void print_search_prompt(void);
void print_search_result(t_history *curr);
void build_search_buff(uint8_t *key, size_t *keylen);
void check_nul_charac(uint8_t buf[BUFF_SIZE + 1], ssize_t rd);
void rl_line_to_hist(int add_to_hist, uint8_t *buff, size_t\
buff_size);
void check_nul_charac(uint8_t buf[BUFF_SIZE + 1], ssize_t rd);
void rl_line_to_hist(int add_to_hist, uint8_t *buff);
#endif

36
src/history/rl_line_to_hist.c

@ -12,58 +12,38 @@
#include "twenty_one_sh.h"
static uint8_t *check_buff_end_for_b(uint8_t *buff, size_t buff_size)
{
if (buff_size <= 0)
return (buff);
if (buff[buff_size - 1] == '\\')
buff[buff_size - 1] = '\0';
return (buff);
}
static void append_line_to_hist(int is_multi, uint8_t *buff,\
size_t buff_size)
static void append_line_to_hist(int is_multi, uint8_t *buff)
{
uint8_t *hist_buff;
uint8_t *tmp;
if (!(tmp = (uint8_t*)ft_strdup((char*)buff)))
fatal_exit(SH_ENOMEM);
tmp = check_buff_end_for_b(tmp, buff_size);
hist_buff = g_shell.hist.history->buf;
if (is_multi == MULTI)
hist_buff = (uint8_t*)ft_strfjoin((char*)hist_buff, "\n", 0);
hist_buff = (uint8_t*)ft_strfjoin((char*)hist_buff, (char*)tmp, 0);
hist_buff = (uint8_t*)ft_strfjoin((char*)hist_buff, (char*)buff, 0);
g_shell.hist.history->buf = hist_buff;
free(tmp);
}
static void create_new_hist_line(uint8_t *buff, size_t buff_size)
static void create_new_hist_line(uint8_t *buff)
{
uint8_t *tmp;
t_history *curr;
if (!(curr = find_last_hist_line()))
curr = g_shell.hist.history;
if (!(tmp = (uint8_t*)ft_strdup((char*)buff)))
fatal_exit(SH_ENOMEM);
tmp = check_buff_end_for_b(tmp, buff_size);
g_shell.hist.history = rl_add_hist(curr, rl_new_hist(tmp));
g_shell.hist.history = rl_add_hist(curr, rl_new_hist(buff));
g_shell.hist.history_size++;
resize_history(g_shell.hist.history);
g_shell.hist.history_save = -1;
free(tmp);
}
void rl_line_to_hist(int add_to_hist, uint8_t *buff, size_t b_size)
void rl_line_to_hist(int add_to_hist, uint8_t *buff)
{
if (g_shell.edit.prompt_id != HEREDOC_PROMPT && add_to_hist == 1)
{
if (g_shell.edit.prompt_id == QUOTE_PROMPT)
append_line_to_hist(MULTI, buff, b_size);
append_line_to_hist(MULTI, buff);
else if (g_shell.edit.prompt_id == BACKSLASH_PROMPT)
append_line_to_hist(1, buff, b_size);
append_line_to_hist(1, buff);
else
create_new_hist_line(buff, b_size);
create_new_hist_line(buff);
}
}

5
src/readline/return_fn.c

@ -32,10 +32,7 @@ static void return_end(uint8_t *buff, size_t buff_size, int add_to_hist)
rl_free_controler(FREE_ALL_EDIT);
write(1, "\n", 1);
g_shell.edit.reading = FALSE;
if (g_shell.edit.prompt_id == BASIC_PROMPT)
buff = (uint8_t *)replace_exclaim((char *)buff,\
g_shell.hist.history, NULL, NULL);
rl_line_to_hist(add_to_hist, buff, buff_size);
rl_line_to_hist(add_to_hist, buff);
buff = (uint8_t *)ft_strfjoin((char *)buff, "\n", 0);
buff_size = ft_u8_strlen(buff);
g_shell.line = buff;

Loading…
Откажи
Сачувај