fixed stuff

This commit is contained in:
Maieul BOYER 2024-07-18 13:34:15 +02:00
parent 8d76630152
commit 95f933c7c7
No known key found for this signature in database
3 changed files with 49 additions and 29 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/11 18:21:45 by maiboyer #+# #+# */
/* Updated: 2024/07/11 18:28:19 by maiboyer ### ########.fr */
/* Updated: 2024/07/18 13:33:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,24 +40,20 @@ t_usize line_get_prompt_len(t_const_str s)
{
t_usize i;
t_usize ret;
t_isize color;
if ((_modify_vars(&i, &ret, false), true) && s == NULL)
return (0);
while (s[i])
{
if (s[i] == '\x1b' && s[i++] == '[')
if (s[i] == '\x1b' && s[i + 1] == '[')
{
color = ((void)(i++), 0);
while (color >= 0)
{
while (((void)color--, true) && s[i] >= '0' && s[i] <= '9')
color += ((void)(i++), 2);
if (s[i] == ';')
i += 2;
while (0x30 <= s[i] && s[i] <= 0x3F)
i++;
while (0x20 <= s[i] && s[i] <= 0x2F)
i++;
if (0x40 <= s[i] && s[i] <= 0x7E)
i++;
else if (s[i] == 'm' && ((void)i++, true))
break ;
}
}
_modify_vars(&i, &ret, true);
}
@ -81,5 +77,6 @@ void line_refresh(t_line_state *state, t_line_flags flags)
me_printf_str(&str, "%s%s\x1b[0G\x1b[%uC", state->prompt,
state->buf.buf, state->pos + line_get_prompt_len(state->prompt));
me_printf_fd(state->output_fd, "%s", str.buf);
//me_eprintf("prompt = %u | pos = %u",line_get_prompt_len(state->prompt) , state->pos);
string_free(str);
}

View file

@ -6,45 +6,44 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */
/* Updated: 2024/07/17 15:38:55 by maiboyer ### ########.fr */
/* Updated: 2024/07/18 13:21:06 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/convert/str_to_numbers.h"
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/matchers/matchers.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include "me/types.h"
#include <stdio.h>
#include <stdlib.h>
t_i32 _atoi_printf(t_const_str s);
bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
t_printf_arg *c_arg)
{
t_str str;
t_usize i;
t_i32 atoi_res;
i = 0;
while (fmt[*c_idx + i] != '\0' && fmt[*c_idx + i] >= '0' && \
fmt[*c_idx + i] <= '9')
i++;
str = str_substring(fmt, *c_idx, i);
if (str == NULL)
atoi_res = _atoi_printf(&fmt[*c_idx]);
if (atoi_res < 0)
{
*c_idx = *nxt;
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
return (false);
}
if (str_to_u64(str, 10, &c_arg->extra.precision))
advance_atoi(fmt, c_idx);
c_arg->extra.align = (t_u64)atoi_res;
handle_prec_and_align(fmt, c_idx, c_arg);
atoi_res = atoi(&fmt[*c_idx]);
if (atoi_res < 0)
{
*c_idx = *nxt;
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
return (mem_free(str), false);
return (false);
}
mem_free(str);
advance_atoi(fmt, c_idx);
c_arg->extra.precision = (t_u64)atoi_res;
return (true);
}

View file

@ -6,10 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:06:15 by maiboyer #+# #+# */
/* Updated: 2023/12/11 19:21:38 by maiboyer ### ########.fr */
/* Updated: 2024/07/18 13:20:35 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/matchers/matchers.h"
#include "me/str/str.h"
@ -51,3 +52,26 @@ void print_sign_if_needed(t_pad_and_stuff_args a, t_printf_arg d,
if (d.flags & (SIGN) && a.sign != NULL)
f(a.sign, a.sign_len, d.p_args);
}
t_i32 _atoi_printf(t_const_str str)
{
t_u64 out;
t_u64 sign;
t_usize i;
out = 0;
i = 0;
sign = 1;
while (me_isspace(str[i]))
i++;
if (str[i] == '+' || str[i] == '-')
if (str[i++] == '-')
sign = -1;
while (me_isdigit(str[i]))
{
out *= 10;
out += str[i] - '0';
i++;
}
return ((t_i32)(out * sign));
}