Skip to content

Commit

Permalink
print: norminette issue + enable CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixailz committed Jan 23, 2024
1 parent 020978b commit ac60359
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
9 changes: 7 additions & 2 deletions inc/libft_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brda-sil <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/22 13:16:35 by brda-sil #+# #+# */
/* Updated: 2023/12/04 02:17:45 by brda-sil ### ########.fr */
/* Updated: 2024/01/23 01:02:52 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -211,6 +211,8 @@ char *ft_printf_buff_get(void);
t_bin ft_printf_fmt_get_flags(int *i, const char *format);

// print/ft_printf/ft_printf_main.c
void ft_printf_fmt_setup(t_fmt_conf *conf, int *i_fmt, \
const char *format);
void ft_printf_fmt_parse(int *i_fmt, int *i_buff, \
const char *format, va_list args);
t_size ft_printf_parse(va_list args, const char *format);
Expand All @@ -230,6 +232,8 @@ void ft_printf_fmt_get_type(t_fmt_conf *conf, va_list args);
t_size ft_printf_fmt_get_width(int *i_fmt, const char *format);

// print/ft_printf/padding/addr.c
void ft_printf_type_padding_addr_short(t_fmt_conf *conf, char *buff, \
t_size str_len);
void ft_printf_type_padding_addr(t_fmt_conf *conf);

// print/ft_printf/padding/char.c
Expand All @@ -245,7 +249,8 @@ void ft_printf_type_padding_hex_pad(t_fmt_conf *conf, t_size begin, \
void ft_printf_type_padding_hex(t_fmt_conf *conf);

// print/ft_printf/padding/integer.c
void ft_printf_type_padding_integer_post(t_fmt_conf *conf, char sign);
void ft_printf_type_padding_integer_post(t_fmt_conf *conf, char sign, \
char *buff);
void ft_printf_type_padding_integer_pad(t_fmt_conf *conf, t_size begin, \
int to_pad);
void ft_printf_type_padding_integer(t_fmt_conf *conf);
Expand Down
20 changes: 13 additions & 7 deletions src/print/ft_printf/ft_printf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@
/* By: brda-sil <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 16:46:32 by brda-sil #+# #+# */
/* Updated: 2024/01/18 15:07:33 by brda-sil ### ########.fr */
/* Updated: 2024/01/23 01:03:02 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft_print.h"

void ft_printf_fmt_setup(t_fmt_conf *conf, int *i_fmt, \
const char *format)
{
conf->i_fmt = i_fmt;
(*conf->i_fmt)++;
conf->flags = ft_printf_fmt_get_flags(i_fmt, format);
conf->width = ft_printf_fmt_get_width(i_fmt, format);
conf->precision = ft_printf_fmt_get_precision(i_fmt, format);
conf->fmt = format;
}

void ft_printf_fmt_parse(int *i_fmt, int *i_buff, \
const char *format, va_list args)
{
t_fmt_conf conf;
char *buff;
t_size str_len;

conf.i_fmt = i_fmt;
(*conf.i_fmt)++;
conf.flags = ft_printf_fmt_get_flags(i_fmt, format);
conf.width = ft_printf_fmt_get_width(i_fmt, format);
conf.precision = ft_printf_fmt_get_precision(i_fmt, format);
ft_printf_fmt_setup(&conf, i_fmt, format);
conf.i_buff = i_buff;
conf.fmt = format;
ft_printf_fmt_get_type(&conf, args);
buff = ft_printf_buff_get();
if (conf.width)
Expand Down
27 changes: 14 additions & 13 deletions src/print/ft_printf/padding/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
/* By: brda-sil <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 15:28:01 by brda-sil #+# #+# */
/* Updated: 2023/12/04 00:37:21 by brda-sil ### ########.fr */
/* Updated: 2024/01/23 01:01:55 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft_print.h"

void ft_printf_type_padding_addr_short(t_fmt_conf *conf, char *buff, \
t_size str_len)
{
if (conf->flags & FT_PRINTF_FLAG_MINUS)
ft_strncpy(buff + *conf->i_buff, conf->cur_type, str_len);
else
ft_strncpy(buff + *conf->i_buff + conf->width - str_len, \
conf->cur_type, str_len);
(*conf->i_buff) += conf->width;
}

void ft_printf_type_padding_addr(t_fmt_conf *conf)
{
t_size begin;
Expand All @@ -25,11 +36,8 @@ void ft_printf_type_padding_addr(t_fmt_conf *conf)
begin = *conf->i_buff;
if (conf->flags & FT_PRINTF_FLAG_MINUS)
begin += str_len;
while (to_pad > 0)
{
while (to_pad-- > 0)
buff[begin++] = ' ';
to_pad--;
}
if (str_len > conf->width)
{
if (conf->flags & FT_PRINTF_FLAG_MINUS)
Expand All @@ -39,12 +47,5 @@ void ft_printf_type_padding_addr(t_fmt_conf *conf)
(*conf->i_buff) += str_len;
}
else
{
if (conf->flags & FT_PRINTF_FLAG_MINUS)
ft_strncpy(buff + *conf->i_buff, conf->cur_type, str_len);
else
ft_strncpy(buff + *conf->i_buff + conf->width - str_len, \
conf->cur_type, str_len);
(*conf->i_buff) += conf->width;
}
ft_printf_type_padding_addr_short(conf, buff, str_len);
}
11 changes: 6 additions & 5 deletions src/print/ft_printf/padding/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
/* By: brda-sil <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 15:28:37 by brda-sil #+# #+# */
/* Updated: 2023/12/04 22:34:44 by brda-sil ### ########.fr */
/* Updated: 2024/01/23 01:01:14 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft_print.h"

void ft_printf_type_padding_integer_post(t_fmt_conf *conf, char sign)
void ft_printf_type_padding_integer_post(t_fmt_conf *conf, char sign, \
char *buff)
{
char *buff;
t_size str_len;

buff = ft_printf_buff_get();
str_len = ft_strlen(conf->cur_type) - (sign != 0);
if (sign && !(conf->flags & FT_PRINTF_FLAG_MINUS))
{
Expand Down Expand Up @@ -68,6 +67,7 @@ void ft_printf_type_padding_integer(t_fmt_conf *conf)
int to_pad;
char sign;
t_size str_len;
char *buff;

sign = ft_printf_type_padding_remove_sign(conf->cur_type);
str_len = ft_strlen(conf->cur_type) - (sign != 0);
Expand All @@ -76,5 +76,6 @@ void ft_printf_type_padding_integer(t_fmt_conf *conf)
if (conf->flags & FT_PRINTF_FLAG_MINUS)
begin += str_len;
ft_printf_type_padding_integer_pad(conf, begin, to_pad);
ft_printf_type_padding_integer_post(conf, sign);
buff = ft_printf_buff_get();
ft_printf_type_padding_integer_post(conf, sign, buff);
}
20 changes: 10 additions & 10 deletions test/src/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brda-sil <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 03:09:08 by brda-sil #+# #+# */
/* Updated: 2023/12/04 22:22:30 by brda-sil ### ########.fr */
/* Updated: 2024/01/23 01:05:20 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -180,13 +180,13 @@ int ci_flags_padding(void)
retv |= test_printf_integer("%-06x", 0x10);
retv |= test_printf_integer("%-#06x", 0x10);

// retv |= test_printf_integer("%#6x", -0x10);
// retv |= test_printf_integer("%06x", -0x10);
// retv |= test_printf_integer("%#06x", -0x10);
// retv |= test_printf_integer("%-6x", -0x10);
// retv |= test_printf_integer("%-#6x", -0x10);
// retv |= test_printf_integer("%-06x", -0x10);
// retv |= test_printf_integer("%-#06x", -0x10);
retv |= test_printf_integer("%#6x", -0x10);
retv |= test_printf_integer("%06x", -0x10);
retv |= test_printf_integer("%#06x", -0x10);
retv |= test_printf_integer("%-6x", -0x10);
retv |= test_printf_integer("%-#6x", -0x10);
retv |= test_printf_integer("%-06x", -0x10);
retv |= test_printf_integer("%-#06x", -0x10);

retv |= test_printf_integer("%6d", 0x10);
retv |= test_printf_integer("%06d", 0x10);
Expand All @@ -208,8 +208,8 @@ int ci_test(void)
int retv;

retv = 0;
// retv |= ci_base();
// retv |= ci_flags_padding();
retv |= ci_base();
retv |= ci_flags_padding();
// ft_dprintf(2, "test\n");
// ft_perr("test [%#06x]\n", 0x10);
printf(" {%01d} \n", -9);
Expand Down

0 comments on commit ac60359

Please sign in to comment.