Commit db55faa4 authored by Gabriel Genois's avatar Gabriel Genois

..

parent 670d417e
Pipeline #100 failed with stages
in 13 seconds
......@@ -18,6 +18,7 @@ typedef struct s_pfdata
int w;
char *input;
int p;
struct s_list *raw;
int s;
int wspace_char;
int neg;
......@@ -27,6 +28,8 @@ typedef struct s_pfdata
void ftpf_tmp_printpfdata(t_pfdata **dt);
int ftpf_numbers_cval(t_list **list);
int ftpf_numbers_counts(t_list **list);
int ftpf_iachar(char c);
int ftpf_ist(char c);
void ftpf_getflagsnw(t_pfdata **dt, va_list *data);
......@@ -57,6 +60,8 @@ void ftpf_isolate(const char **str, char **src, int *ipos);
void ftpf_core(const char **str, va_list *data, int *istatus);
int ft_printf(const char *str, ...);
int ft_atoi(const char *str);
char *ft_luitoa_base(long unsigned int nbr, size_t base);
char *ft_uitoa_base(unsigned int nbr, size_t base);
char *ft_litoa_base(long signed int nbr, int base);
......
......@@ -11,6 +11,7 @@ typedef struct s_list
struct s_list *next;
} t_list;
int ft_atoi(const char *str);
void ft_lstcutat(t_list **lst, int count);
char *ft_luitoa_base(long unsigned int nbr, size_t base);
char *ft_uitoa_base(unsigned int nbr, size_t base);
......
......@@ -6,7 +6,7 @@
# By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ #
# #+# #+ #+ #+# #
# Created: 2017/11/23 11:34:53 by ggenois #+# ## ## #+# #
# Updated: 2018/03/08 16:17:24 by ggenois ### #+. /#+ ###.fr #
# Updated: 2018/11/04 21:24:05 by ggenois ### #+. /#+ ###.fr #
# / #
# / #
# **************************************************************************** #
......@@ -34,7 +34,8 @@ lst/ft_lstcutat.c\
lst/ft_lstwipe.c\
out/ft_putchar.c \
out/ft_putstr.c \
out/ft_putnbr.c
out/ft_putnbr.c\
str/ft_atoi.c
PROJECT = libft
NAME = $(PROJECT).a
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2017/11/13 11:35:34 by ggenois #+# ## ## #+# */
/* Updated: 2018/02/26 10:55:52 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:19:30 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -22,7 +22,6 @@ void *ft_memcpy(void *dst, const void *src, size_t n)
nb = -1;
odst = (char*) dst;
osrc = (char*) src;
while (++nb < n)
odst[nb] = osrc[nb];
return (dst);
......
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_atoi.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2017/09/21 11:31:23 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 21:24:25 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "../../includes/libft.h"
int ft_atoi(const char *str)
{
int mod;
int res;
mod = 1;
res = 0;
while (*str == ' ' || (*str >= '\a' && *str <= '\r'))
str++;
if (*str == '-' || *str == '+')
mod = *str++ == '-' ? -1 : 1;
while (*str >= '0' && *str <= '9')
res = res * 10 + (*str++ - '0');
return (res * mod);
}
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:03:09 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 19:52:46 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:29:58 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -186,7 +186,17 @@ 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("{%-15Z}", 123);
//i = ft_printf("{%-15Z}", 123);
//i = ft_printf("%0 d", 42);
//i = ft_printf("@main_ftprintf: %####0000 33..1..#00d\\n", 256);
//i = ft_printf("{% 03d}", 0);
//i = ft_printf("%.4x", 42);
//i = ft_printf("% 10.5d", 4242);
//i = ft_printf("@moulitest: %.10d", -42);
//ft_putchar('\n');
//ft_putnbr(i);
//ft_putchar('\n');
i = ft_printf("%S", L"米");
ft_putchar('\n');
//i = ft_printf("% h");
//ft_putchar('\n');
......
......@@ -14,13 +14,25 @@ int ftpf_getwcharlen(wchar_t wchar)
if (wchar == 0)
return (0);
else if (wchar <= 0x7f)
{
ft_putstr("wsize:1\n");
return (1);
}
else if (wchar <= 0x7ff)
{
ft_putstr("wsize:2\n");
return (2);
}
else if (wchar <= 0xffff)
{
ft_putstr("wsize:3\n");
return (3);
}
else
{
ft_putstr("wsize:4\n");
return (4);
}
}
char *ftpf_charfromwchar(wchar_t wchar)
......@@ -31,26 +43,26 @@ char *ftpf_charfromwchar(wchar_t wchar)
i = 0;
wsize = ftpf_getwcharlen(wchar);
str = ft_strnew(wsize + 1);
str = ft_strnew(wsize);
if (wsize == 1)
str[i++] = wchar;
else if (wsize == 2)
{
str[i++] = (wchar >> 6) + 0xC0;
str[i++] = (wchar & 0x3F) + 0x80;
str[i] = (wchar & 0x3F) + 0x80;
}
else if (wsize == 3)
{
str[i++] = (wchar >> 12) + 0xE0;
str[i++] = ((wchar >> 6) & 0x3F) + 0x80;
str[i++] = (wchar & 0x3F) + 0x80;
str[i] = (wchar & 0x3F) + 0x80;
}
else if (wsize > 3)
{
str[i++] = (wchar >> 18) + 0xF0;
str[i++] = ((wchar >> 12) & 0x3F) + 0x80;
str[i++] = ((wchar >> 6) & 0x3F) + 0x80;
str[i++] = (wchar & 0x3F) + 0x80;
str[i] = (wchar & 0x3F) + 0x80;
}
return (str);
}
......@@ -59,12 +71,15 @@ int ft_lstfromwchar(t_pfdata **dt, wchar_t *item)
{
int ilenght;
char *buffer;
wchar_t tmp;
char c;
ilenght = 0;
if(!item)
{
buffer = ftpf_strings_null();
ft_lstfromstr(&(*dt)->data, &buffer);
free(buffer);
return (-1);
}
......@@ -73,9 +88,18 @@ int ft_lstfromwchar(t_pfdata **dt, wchar_t *item)
ilenght++;
while (ilenght-- >= 0)
{
buffer = ftpf_charfromwchar((*(--item)));
tmp = *(--item);
buffer = ftpf_charfromwchar(tmp);
//write(0, &buffer, ftpf_getwcharlen(tmp));
//ft_lstadd(&(*dt)->data, ft_lstnew(&buffer, ftpf_getwcharlen(tmp)));
c = '-';
ft_lstfromstr(&(*dt)->data, &buffer);
ft_lstadd(&(*dt)->data, ft_lstnew(&c, sizeof(char)));
free(buffer);
}
ftpf_tmp_printpfdata(dt);
return (ilenght);
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:08:31 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 18:25:01 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:30:53 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -20,11 +20,29 @@ int ftpf_nis(char c)
return (0);
}
void ftpf_numbers_put_sign(t_pfdata **dt)
int ftpf_numbers_cval(t_list **list)
{
t_list *ref;
int nb;
int i;
nb = 0;
ref = (*list);
while (ref)
{
i = ft_atoi(ref->content);
nb = nb + i;
ref = ref->next;
}
return (nb);
}
void ftpf_numbers_put_sign(t_pfdata **dt, int *size)
{
char tmp;
t_list *item;
if (size) {}
if(ftpf_nis((*dt)->t) == 0)
return ;
if (ftpf_iscinlist(&(*dt)->f, '+') || ftpf_iscinlist(&(*dt)->f, ' '))
......@@ -34,12 +52,25 @@ void ftpf_numbers_put_sign(t_pfdata **dt)
if ((*dt)->neg == 0)
{
if(ftpf_iscinlist(&(*dt)->f, '+'))
{
tmp = '+';
item = ft_lstnew(&tmp, sizeof(char));
ft_lstadd(&(*dt)->data, item);
}
else
tmp = ' ';
item = ft_lstnew(&tmp, sizeof(char));
ft_lstadd(&(*dt)->data, item);
{
if (ftpf_numbers_cval(&(*dt)->data) == 0 && (*dt)->t == 'd' && ftpf_iscinlist(&(*dt)->f, ' ') && ftpf_iscinlist(&(*dt)->f, '0'))
(*size) = (*size) + 1;
else
{
tmp = ' ';
item = ft_lstnew(&tmp, sizeof(char));
ft_lstadd(&(*dt)->data, item);
}
}
}
}
}
......@@ -49,11 +80,17 @@ int ftpf_numbers_counts(t_list **list)
{
t_list *ref;
int nb;
//int i;
ref = (*list);
nb = (ftpf_getcfl(list) == '-' ? -1 : 0);
while (ref)
{
//i = ft_atoi(ref->content);
//ft_putstr("[[");
//ft_putnbr(i);
//ft_putstr("]]\n");
nb = nb + 1;
ref = ref->next;
}
......@@ -104,6 +141,7 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
ilen++;
}
} else {
//ftpf_tmp_printpfdata(dt);
c = '0';
if (ftpf_iscinlist(&(*dt)->f, '+'))
{
......@@ -111,22 +149,33 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
(*size)--;
}
else if (ftpf_iscinlist(&(*dt)->f, ' '))
{
write(1, " ", 1);
}
else if(writen != 0)
{
if(((*dt)->w - ftpf_numbers_counts(&(*dt)->data)) > 0)
{
writen--;
ft_lstadd(&(*dt)->data, ft_lstnew(&c, sizeof(char)));
}
(*size)--;
}
//ftpf_tmp_printpfdata(dt);
if (writen != 0 && ftpf_numbers_cval(&(*dt)->data) == 0)
{
if(((*dt)->w - ftpf_numbers_counts(&(*dt)->data)) > 0)
{
writen--;
ft_lstadd(&(*dt)->data, ft_lstnew(&c, sizeof(char)));
}
(*size)--;
}
}
(*size)++;
}
while (--ilen >= 0)
{
if ((*dt)->p < 0 || ((*dt)->p >= 0 && writen > 0))
......@@ -144,6 +193,7 @@ void ftpf_numbers_put_lefpad(t_pfdata **dt, int *size)
(*dt)->w = ((*dt)->w > (*dt)->p ? (*dt)->w - (*dt)->p : 0);
else
(*dt)->w = 0;
}
}
......@@ -156,10 +206,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);
ftpf_numbers_put_sign(dt, &size);
//ftpf_tmp_printpfdata(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/11/04 17:16:36 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 23:31:03 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -15,6 +15,9 @@
void ftpf_precision_add(t_list **lst, char c, int nb)
{
//ft_putnbr(nb);
//ft_putnbr(ftpf_numbers_counts(lst));
//nb = nb - ftpf_numbers_counts(lst);
while (nb-- > 0)
ft_lstadd(lst, ft_lstnew(&c, sizeof(char)));
}
......@@ -28,6 +31,7 @@ void ftpf_apply_precision_insert(int i, t_pfdata **dt, int dz)
if (i < 0)
return ;
i = (*dt)->p - i;
m = 0;
c = '0';
if (dz == 0)
......@@ -39,13 +43,21 @@ void ftpf_apply_precision_insert(int i, t_pfdata **dt, int dz)
(*dt)->w = ((*dt)->p > 0 ? (*dt)->w + (*dt)->p : (*dt)->w);
return ;
}
if (!ft_isdigit(ftpf_getcfl(&(*dt)->data)))
{
if (ftpf_iscinlist(&(*dt)->data, '-'))
{
i = i - 1;
}
m = ftpf_getcfl(&(*dt)->data);
tmp = (*dt)->data->next;
free((*dt)->data->content);
free((*dt)->data);
(*dt)->data = tmp;
if (!ftpf_iscinlist(&(*dt)->data, '-'))
i = i + 1;
}
ftpf_precision_add(&(*dt)->data, c, i);
c = '-';
......@@ -55,12 +67,10 @@ void ftpf_apply_precision_insert(int i, t_pfdata **dt, int dz)
void ftpf_precision(t_pfdata **dt)
{
t_list *ref;
int i;
int dz;
i = 0;
ref = (*dt)->data;
dz = 1;
if ((*dt)->p >= 0)
......@@ -72,16 +82,8 @@ void ftpf_precision(t_pfdata **dt)
else
{
dz = 0;
while (ref)
{
if (ft_isdigit(ftpf_getcfl(&ref)))
{
dz = dz + (ftpf_getcfl(&ref) - '0');
i++;
}
ref = ref->next;
}
i = ftpf_numbers_counts(&(*dt)->data);
dz = ftpf_numbers_cval(&(*dt)->data);
}
}
if (ftpf_istypenum((*dt)->t))
......
......@@ -6,18 +6,32 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:09:47 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 19:52:13 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:28:50 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
void ftpf_wmemcpy(void *dst, void *src, size_t n)
{
wchar_t *odst;
wchar_t *osrc;
size_t nb;
nb = -1;
odst = (wchar_t*) dst;
osrc = (wchar_t*) src;
while (++nb < n)
odst[nb] = osrc[nb];
}
int ftpf_strings_w(t_pfdata **dt, va_list *data)
{
wchar_t c;
wchar_t *ws;
t_list *tw;
int l;
char *tmp;
l = 1;
if ((*dt)->t == 'C' || (*dt)->t == 'c')
{
......@@ -26,13 +40,33 @@ int ftpf_strings_w(t_pfdata **dt, va_list *data)
(*dt)->data = ft_lstnew(&c, sizeof(char));
else
{
tmp = ftpf_charfromwchar(c);
ft_lstfromstr(&(*dt)->data, &tmp);
free(tmp);
ft_lstadd(&(*dt)->data,ft_lstnew(&c, sizeof(wchar_t)));
//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 *));
{
ws = va_arg((*data), wchar_t *);
while ((*(++ws)))
l++;
tw = (t_list *) malloc(sizeof(t_list));
tw->content_size = sizeof(wchar_t);
tw->content = (wchar_t *) malloc (sizeof(wchar_t));
tw->next = NULL;
ftpf_wmemcpy(tw, ws, 1);
ft_lstadd(&(*dt)->data,tw);
//l = ft_lstfromwchar(dt, va_arg((*data), wchar_t *));
}
ftpf_tmp_printpfdata(dt);
return (l);
}
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:09:59 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 16:30:40 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:31:21 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -70,6 +70,7 @@ t_pfdata *ftpf_initcontainer()
return (NULL);
dt->data = NULL;
dt->f = NULL;
dt->raw = NULL;
dt->input = NULL;
dt->wspace_char = ' ';
dt->w = 0;
......@@ -96,7 +97,9 @@ void ftpf_types(char **input, va_list *data, int *size)
|| dt->t == 'c' || dt->t == 'C')
{
ftpf_strings(&dt, data);
ftpf_numbers_put_lefpad(&dt, size);
//ftpf_tmp_printpfdata(&dt);
}
else if (dt->t != '%')
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:10:25 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 17:56:31 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/04 22:24:31 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -60,6 +60,7 @@ char ftpf_getcfl(t_list **lst)
void ftpf_numbers_put_ox(t_pfdata **dt, int mode)
{
if ((*dt)->s < 0)
return ;
(*dt)->s = 0;
......
......@@ -6,7 +6,7 @@
/* By: ggenois <ggenois@student.le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/05/19 16:10:59 by ggenois #+# ## ## #+# */
/* Updated: 2018/11/04 19:55:20 by ggenois ### #+. /#+ ###.fr */
/* Updated: 2018/11/05 00:27:55 by ggenois ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
......@@ -40,27 +40,23 @@ int ftpf_write(t_pfdata **dt)
tlen = 0;
ftpf_precision(dt);
//ftpf_tmp_printpfdata(dt);
wspace = (*dt)->w - ft_lstcount(&(*dt)->data);
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);
if ((*dt)->t == 'S' || (*dt)->t == 's')
write(1, ftpf_charfromwchar((wchar_t)tmp_data->content), ftpf_getwcharlen((wchar_t)tmp_data->content));
else
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