fixed stuff
This commit is contained in:
parent
8d76630152
commit
95f933c7c7
3 changed files with 49 additions and 29 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/11 18:21:45 by maiboyer #+# #+# */
|
/* 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 i;
|
||||||
t_usize ret;
|
t_usize ret;
|
||||||
t_isize color;
|
|
||||||
|
|
||||||
if ((_modify_vars(&i, &ret, false), true) && s == NULL)
|
if ((_modify_vars(&i, &ret, false), true) && s == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
while (s[i])
|
while (s[i])
|
||||||
{
|
{
|
||||||
if (s[i] == '\x1b' && s[i++] == '[')
|
if (s[i] == '\x1b' && s[i + 1] == '[')
|
||||||
{
|
{
|
||||||
color = ((void)(i++), 0);
|
i += 2;
|
||||||
while (color >= 0)
|
while (0x30 <= s[i] && s[i] <= 0x3F)
|
||||||
{
|
i++;
|
||||||
while (((void)color--, true) && s[i] >= '0' && s[i] <= '9')
|
while (0x20 <= s[i] && s[i] <= 0x2F)
|
||||||
color += ((void)(i++), 2);
|
i++;
|
||||||
if (s[i] == ';')
|
if (0x40 <= s[i] && s[i] <= 0x7E)
|
||||||
i++;
|
i++;
|
||||||
else if (s[i] == 'm' && ((void)i++, true))
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_modify_vars(&i, &ret, true);
|
_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,
|
me_printf_str(&str, "%s%s\x1b[0G\x1b[%uC", state->prompt,
|
||||||
state->buf.buf, state->pos + line_get_prompt_len(state->prompt));
|
state->buf.buf, state->pos + line_get_prompt_len(state->prompt));
|
||||||
me_printf_fd(state->output_fd, "%s", str.buf);
|
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);
|
string_free(str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,45 +6,44 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */
|
/* 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/mem/mem.h"
|
||||||
#include "me/printf/formatter/utils.h"
|
#include "me/printf/formatter/utils.h"
|
||||||
#include "me/printf/matchers/matchers.h"
|
#include "me/printf/matchers/matchers.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include "me/str/str.h"
|
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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,
|
bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
|
||||||
t_printf_arg *c_arg)
|
t_printf_arg *c_arg)
|
||||||
{
|
{
|
||||||
t_str str;
|
t_i32 atoi_res;
|
||||||
t_usize i;
|
|
||||||
|
atoi_res = _atoi_printf(&fmt[*c_idx]);
|
||||||
i = 0;
|
if (atoi_res < 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)
|
|
||||||
{
|
{
|
||||||
*c_idx = *nxt;
|
*c_idx = *nxt;
|
||||||
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
|
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
|
||||||
return (false);
|
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;
|
*c_idx = *nxt;
|
||||||
*nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt);
|
*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);
|
advance_atoi(fmt, c_idx);
|
||||||
|
c_arg->extra.precision = (t_u64)atoi_res;
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,11 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/16 18:06:15 by maiboyer #+# #+# */
|
/* 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/formatter/utils.h"
|
||||||
#include "me/printf/matchers/matchers.h"
|
#include "me/printf/matchers/matchers.h"
|
||||||
#include "me/str/str.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)
|
if (d.flags & (SIGN) && a.sign != NULL)
|
||||||
f(a.sign, a.sign_len, d.p_args);
|
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));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue