Commit dd6fe845 authored by Gabriel Genois's avatar Gabriel Genois

yas

parent 5cfbcb91
Pipeline #98 passed with stages
in 1 minute 5 seconds
......@@ -27,6 +27,11 @@ typedef struct s_pfdata
void ftpf_tmp_printpfdata(t_pfdata **dt);
int ftpf_iachar(char c);
int ftpf_ist(char c);
void ftpf_getflagsnw(t_pfdata **dt, va_list *data);
t_pfdata *ftpf_initcontainer();
int ftpf_notypes(const char **input, int *size, int *ipos);
int ftpf_getwcharlen(wchar_t wchar);
char *ftpf_charfromwchar(wchar_t wchar);
char *ftpf_strings_null(void);
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:03:09 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 15:32:47 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 19:27:02 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -186,7 +186,7 @@ int main(int argc, char **argv)
//i = ft_printf("%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S%S", L"Α α", L"Β β", L"Γ γ", L"Δ δ", L"Ε ε", L"Ζ ζ", L"Η η", L"Θ θ", L"Ι ι", L"Κ κ", L"Λ λ", L"Μ μ", L"Ν ν", L"Ξ ξ", L"Ο ο", L"Π π", L"Ρ ρ", L"Σ σ", L"Τ τ", L"Υ υ", L"Φ φ", L"Χ χ", L"Ψ ψ", L"Ω ω", L"");
//i = ft_printf("\n%D", 9223372036854775807);
//i = ft_printf("\n%D", 9583444433307);
i = ft_printf("%X", 42);
i = ft_printf("% ", "test");
ft_putchar('\n');
ft_putnbr(i);
}
......
......@@ -6,7 +6,7 @@
# By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ #
# #+# #+ #+ #+# #
# Created: 2017/11/23 11:34:53 by ggenois #+# ## ## #+# #
# Updated: 2018/11/03 22:45:08 by ggenois ### #+. /#+ ###.fr #
# Updated: 2018/11/04 16:30:52 by ggenois ### #+. /#+ ###.fr #
# / #
# / #
# **************************************************************************** #
......@@ -22,6 +22,7 @@ ftpf_get_n.c\
ftpf_flags.c\
ftpf_width.c\
ftpf_lstw.c\
ftpf_notypes.c\
ftpf_precision.c
PROJECT = libftprintf
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/09/04 13:56:21 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/03 21:57:54 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 19:17:44 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -17,6 +17,7 @@ void ftpf_core(const char **str, va_list *data, int *size)
{
int i;
char *src;
int nt;
i = -1;
src = NULL;
......@@ -24,15 +25,22 @@ void ftpf_core(const char **str, va_list *data, int *size)
{
if ((*str)[i] == '%')
{
nt = i;
ftpf_isolate(str, &src, &i);
if (src != NULL)
ftpf_types(&src, data, size);
else
{
ftpf_notypes(str, size, &nt);
i = nt;
}
}
else
{
(*size) = (*size) + 1;
ft_putchar((*str)[i]);
}
}
}
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:07:38 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 15:31:06 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 17:46:37 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:08:08 by ggenois #+# ## ## #+# */
/* Updated: 2018/09/06 14:08:29 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 19:15:03 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......
......@@ -11,7 +11,9 @@ char *ftpf_strings_null(void)
int ftpf_getwcharlen(wchar_t wchar)
{
if (wchar <= 0x7f)
if (wchar == 0)
return (0);
else if (wchar <= 0x7f)
return (1);
else if (wchar <= 0x7ff)
return (2);
......@@ -23,7 +25,6 @@ int ftpf_getwcharlen(wchar_t wchar)
char *ftpf_charfromwchar(wchar_t wchar)
{
char *str;
int i;
int wsize;
......@@ -44,7 +45,7 @@ char *ftpf_charfromwchar(wchar_t wchar)
str[i++] = ((wchar >> 6) & 0x3F) + 0x80;
str[i++] = (wchar & 0x3F) + 0x80;
}
else
else if (wsize > 3)
{
str[i++] = (wchar >> 18) + 0xF0;
str[i++] = ((wchar >> 12) & 0x3F) + 0x80;
......
/* ************************************************************************** */
/* LE - / */
/* / */
/* ftpf_notypes.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/11/04 17:13:25 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 19:28:03 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
int ftpf_notypes(const char **input, int *size, int *ipos)
{
t_pfdata *dt;
int ilen;
int itlen;
int i;
i = (*ipos);
dt = ftpf_initcontainer();
itlen = 0;
while ((*input)[i] != '\0' && ftpf_iachar((*input)[i]) == 1)
++i;
ilen = i - (*ipos);
dt->input = ft_strsub((*input), (*ipos), ilen);
//ft_putstr(dt->input );
ftpf_flags(&dt, &itlen);
ftpf_flags_widecheck(&dt);
ftpf_width(&dt, NULL, &itlen);
--dt->w;
(*size) = (*size) + ftpf_write(&dt);
(*ipos) = (*ipos) + (ilen - 1);
return (0);
}
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:08:31 by ggenois #+# ## ## #+# */
/* Updated: 2018/09/06 16:29:54 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 18:25:01 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -67,7 +67,7 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
int writen;
t_list *tmp;
char *ctmp;
writen = ((*dt)->p > 0 ? (*dt)->p - ftpf_numbers_counts(&(*dt)->data) : -1);
c = ftpf_getcfl(&(*dt)->data);
if (ftpf_iscinlist(&(*dt)->f, '0') && !ftpf_iscinlist(&(*dt)->f, '-'))
......@@ -92,6 +92,7 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
ctmp = ft_strnew(2);
ctmp[0] = '0';
(*dt)->data->content = ctmp;
writen--;
}
else
......@@ -113,19 +114,21 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
write(1, " ", 1);
else if(writen != 0)
{
if(writen != 0)
if(((*dt)->w - ftpf_numbers_counts(&(*dt)->data)) > 0)
{
writen--;
ft_lstadd(&(*dt)->data, ft_lstnew(&c, sizeof(char)));
(*size)--;
}
(*size)--;
}
}
(*size)++;
}
while (--ilen >= 0)
{
if ((*dt)->p < 0 || ((*dt)->p >= 0 && writen > 0))
{
c = '0';
......@@ -153,7 +156,9 @@ int ftpf_numbers(t_pfdata **dt, va_list *data)
src = ftpf_get_n(dt, data);
ft_lstfromstr(&(*dt)->data, &src);
free(src);
ftpf_numbers_put_lefpad(dt, &size);
ftpf_numbers_put_ox(dt, 1);
ftpf_numbers_put_sign(dt);
return (size);
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:09:24 by ggenois #+# ## ## #+# */
/* Updated: 2018/09/06 13:28:14 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 17:16:36 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:09:47 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 14:27:53 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 18:29:28 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -22,9 +22,14 @@ int ftpf_strings_w(t_pfdata **dt, va_list *data)
if ((*dt)->t == 'C' || (*dt)->t == 'c')
{
c = va_arg((*data), wchar_t);
tmp = ftpf_charfromwchar(c);
ft_lstfromstr(&(*dt)->data, &tmp);
free(tmp);
if (c == 0)
(*dt)->data = ft_lstnew(&c, sizeof(char));
else
{
tmp = ftpf_charfromwchar(c);
ft_lstfromstr(&(*dt)->data, &tmp);
free(tmp);
}
}
else if ((*dt)->t == 'S' || (*dt)->t == 's')
l = ft_lstfromwchar(dt, va_arg((*data), wchar_t *));
......@@ -60,11 +65,24 @@ int ftpf_string_n(t_pfdata **dt, va_list *data)
int ftpf_string_p(t_pfdata **dt, va_list *data)
{
char *src;
int i;
i = 0;
if ((*dt)->t == 'p')
{
src = ft_luitoa_base(va_arg((*data), size_t), 16);
ft_lstfromstr(&(*dt)->data, &src);
if ((*dt)->w > 0)
{
if (ftpf_iscinlist(&(*dt)->f, '0'))
{
(*dt)->w = (*dt)->w - 2;
if ((*dt)->w < 0)
(*dt)->w = 0;
ftpf_numbers_put_lefpad(dt, &i);
}
}
ftpf_numbers_put_ox(dt, 1);
free(src);
}
......@@ -75,10 +93,10 @@ void ftpf_strings(t_pfdata **dt, va_list *data)
{
int l;
l = ftpf_getlength(dt);
if (l == 3 || (*dt)->t == 'C' || (*dt)->t == 'S')
if ((*dt)->t == 'p')
ftpf_string_p(dt, data);
else if (l == 3 || (*dt)->t == 'C' || (*dt)->t == 'S')
ftpf_strings_w(dt, data);
else if ((*dt)->t == 'c' || (*dt)->t == 's')
ftpf_string_n(dt, data);
else if ((*dt)->t == 'p')
ftpf_string_p(dt, data);
}
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:09:59 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/03 22:15:59 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 16:30:40 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:10:25 by ggenois #+# ## ## #+# */
/* Updated: 2018/05/19 16:10:47 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 17:56:31 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -65,6 +65,7 @@ void ftpf_numbers_put_ox(t_pfdata **dt, int mode)
(*dt)->s = 0;
if (ftpf_iscinlist(&(*dt)->f, '#') || (*dt)->t == 'p')
{
if (mode)
{
if ((*dt)->t == 'x' || (*dt)->t == 'p')
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/09/06 14:43:05 by ggenois #+# ## ## #+# */
/* Updated: 2018/09/06 14:44:44 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 16:53:47 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:10:59 by ggenois #+# ## ## #+# */
/* Updated: 2018/09/06 16:24:07 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 19:04:41 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -41,18 +41,26 @@ int ftpf_write(t_pfdata **dt)
tlen = 0;
ftpf_precision(dt);
wspace = (*dt)->w - ft_lstcount(&(*dt)->data);
//ftpf_tmp_printpfdata(dt);
if (!w_width(&(*dt)->f))
{
ftpf_write_w(wspace, (*dt)->wspace_char, dt);
}
tmp_data = (*dt)->data;
while (tmp_data)
{
tlen++;
write(1, tmp_data->content, tmp_data->content_size);
tmp_data = tmp_data->next;
}
//ftpf_tmp_printpfdata(dt);
if(w_width(&(*dt)->f))
{
ftpf_write_w(wspace, ' ', dt);
}
tlen = tlen + (wspace > 0 ? wspace : 0);
return (tlen);
}
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment