summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c62
1 files changed, 22 insertions, 40 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 4e74d87..cea3cce 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -20,7 +20,7 @@
#include "c_ctrls.h"
#include "c_init.h"
#include "c_keys.h"
-#include "c_keys_next.h"
+#include "c_utils_next.h"
#include "c_input.h"
#include "c_utils.h"
#include "d_define.h"
@@ -76,21 +76,24 @@ static short
return (0);
}
-char *ft_strrbavchr(const char *s, int c, size_t start)
+static void
+ c_set_ptr_norme(char key, t_bool *sw, char **p, char **context)
{
- size_t i;
-
- i = ft_strlen(s) - start;
- while (s[i] != c)
+ if ((key == -1 && *p - *context != 0) || key == 1)
{
- if (i == 0)
- return (NULL);
- i--;
+ *p += (key == -1) ? (2 * key) : (0);
+ while (*sw == FALSE && ((key == -1 && *p - *context != 0) || key == 1)
+ && **p != C_LF && **p != C_NUL)
+ *p += key;
+ if (*sw == TRUE)
+ *sw = FALSE;
+ if (*p - *context != 0 && **p != C_NUL)
+ *p += 1;
}
- return ((char*)&s[i]);
}
-char *c_set_ptr(t_bool reset, char key, t_msh *msh)
+char
+ *c_set_ptr(t_bool reset, char key, t_msh *msh)
{
static char *p = NULL;
static char *context = NULL;
@@ -109,51 +112,28 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh)
context = msh->prev_hist;
}
if (key == 1 && context == msh->prev_hist
- && p == ft_strrbavchr(msh->prev_hist, '\n', 2) + 1)
+ && p == ft_strrnchr(msh->prev_hist, '\n', 2) + 1)
{
p = msh->curr_hist_ptr;
context = msh->curr_hist_ptr;
sw = TRUE;
}
- if ((key == -1 && p - context != 0) || key == 1)
- {
- p += (key == -1) ? (2 * key) : (0);
- while (sw == FALSE && ((key == -1 && p - context != 0) || key == 1)
- && *p != C_LF && *p != C_NUL)
- p += key;
- if (sw == TRUE)
- sw = FALSE;
- if (p - context != 0 && *p != C_NUL)
- p += 1;
- }
+ c_set_ptr_norme(key, &sw, &p, &context);
return (p);
}
-/* TODO : key_up_down should manage and set the correct key */
-
static char
*c_process_key(char **line, char *buf, t_caps *tcaps, t_msh *msh)
{
- char *ptr;
-
- if (*line == NULL)
- if (!(*line = ft_calloc(1, sizeof(char))))
- return (NULL);
if (ft_isprint(buf[0]))
c_add_char(line, buf, tcaps);
else if (((*((unsigned int *)buf)) == UP_K) ||
- ((*((unsigned int *)buf)) == CTRL_P))
- {
- ptr = c_set_ptr(FALSE, -1, msh);
- c_key_up_down(line, tcaps, ptr);
- c_redraw_line(*line, tcaps);
- }
- else if (((*((unsigned int *)buf)) == DOWN_K) ||
+ ((*((unsigned int *)buf)) == CTRL_P) ||
+ ((*((unsigned int *)buf)) == DOWN_K) ||
((*((unsigned int *)buf)) == CTRL_N))
{
- ptr = c_set_ptr(FALSE, 1, msh);
- c_key_up_down(line, tcaps, ptr);
- c_redraw_line(*line, tcaps);
+ tcaps->key = c_set_key(buf);
+ c_key_up_down(line, tcaps, msh);
}
else if ((*((unsigned int *)buf)) == DEL_K)
{
@@ -183,6 +163,8 @@ short
msh->sig = 0;
tcaps.plen = (unsigned int)m_plen(msh->ps[psx - 1]);
*line = NULL;
+ if (!(*line = ft_calloc(sizeof(char), 1)))
+ return (-1);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
while (!(ft_strchr(nread, '\n')))