properly started project
This commit is contained in:
40
Makefile
40
Makefile
@@ -1,40 +0,0 @@
|
|||||||
#******************************************************************************#
|
|
||||||
# #
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2018/05/05 19:22:36 by tmaze #+# #+# #
|
|
||||||
# Updated: 2018/05/05 19:39:15 by tmaze ### ########.fr #
|
|
||||||
# #
|
|
||||||
#******************************************************************************#
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
CCFLAGS = -Wall -Werror -Wextra
|
|
||||||
CCSTD =
|
|
||||||
|
|
||||||
NAME = libftprintf
|
|
||||||
|
|
||||||
SRCS = convert_d_i.c ft_printf.c main.c
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
|
||||||
INCLS = -I.
|
|
||||||
LIBS = -L. -lft
|
|
||||||
|
|
||||||
.PHONY = all clean fclean re
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): $(OBJS)
|
|
||||||
$(CC) $(CCFLAGS) $(CCSTD) $(INCLS) $^ -o $@ $(LIBS)
|
|
||||||
|
|
||||||
%.o: %.c libftprintf.h
|
|
||||||
$(CC) $(CCFLAGS) $(CCSTD) $(INCLS) -c $< -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(OBJS)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
rm -f $(NAME)
|
|
||||||
|
|
||||||
re: fclean all
|
|
@@ -1,84 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* convert_d_i.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2018/05/05 19:17:53 by tmaze #+# #+# */
|
|
||||||
/* Updated: 2018/05/05 19:40:49 by tmaze ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftprintf.h"
|
|
||||||
|
|
||||||
char *apply_precision_d(char *s, int prec)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
char *tmp;
|
|
||||||
int nb_fill;
|
|
||||||
|
|
||||||
nb_fill = prec - ft_strlen(s);
|
|
||||||
if ((ret = ft_strsub(s, 0, prec)) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
ft_strdel(&s);
|
|
||||||
if (nb_fill > 0 && (s = ft_strnew(nb_fill)) != NULL)
|
|
||||||
{
|
|
||||||
ft_memset(s, '0', nb_fill);
|
|
||||||
tmp = ft_strjoin(s, ret);
|
|
||||||
ft_strdel(&s);
|
|
||||||
ft_strdel(&ret);
|
|
||||||
ret = tmp;
|
|
||||||
tmp = NULL;
|
|
||||||
}
|
|
||||||
ft_strdel(&tmp);
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *apply_width_d(char *s, int width, char align)
|
|
||||||
{
|
|
||||||
char *add;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
if ((add = ft_strnew(width - ft_strlen(s))) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
ft_memset(add, ' ', width - ft_strlen(s));
|
|
||||||
if (align == '-')
|
|
||||||
{
|
|
||||||
tmp = add;
|
|
||||||
add = s;
|
|
||||||
s = tmp;
|
|
||||||
}
|
|
||||||
tmp = ft_strjoin(add, s);
|
|
||||||
ft_strdel(&add);
|
|
||||||
ft_strdel(&s);
|
|
||||||
return (tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *convert_d_i(char *flags, int *dim, int nb)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
char *tmp;
|
|
||||||
char *atoi;
|
|
||||||
int atoi_len;
|
|
||||||
|
|
||||||
atoi = ft_itoa(ft_abs(nb));
|
|
||||||
atoi_len = ft_strlen(atoi);
|
|
||||||
if (dim[1] > atoi_len)
|
|
||||||
tmp = apply_precision_d(atoi, dim[1]);
|
|
||||||
else
|
|
||||||
tmp = atoi;
|
|
||||||
atoi = ft_strnew((((flags[1] == '+' || flags[1] == ' ') && nb >= 0) || nb < 0) ? 1 : 0);
|
|
||||||
if (flags[1] == '+' && nb >= 0)
|
|
||||||
atoi[0] = '+';
|
|
||||||
else if (flags[1] == ' ' && nb >= 0)
|
|
||||||
atoi[0] = ' ';
|
|
||||||
else if (nb <= 0)
|
|
||||||
atoi[0] = '-';
|
|
||||||
ret = ft_strjoin(atoi, tmp);
|
|
||||||
ft_strdel(&atoi);
|
|
||||||
ft_strdel(&tmp);
|
|
||||||
if ((size_t)dim[0] > ft_strlen(ret))
|
|
||||||
ret = apply_width_d(ret, dim[0], flags[0]);
|
|
||||||
return (ret);
|
|
||||||
}
|
|
81
ft_printf.c
81
ft_printf.c
@@ -1,81 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_printf.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2018/05/05 19:36:58 by tmaze #+# #+# */
|
|
||||||
/* Updated: 2018/05/05 19:38:02 by tmaze ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftprintf.h"
|
|
||||||
|
|
||||||
int is_flag(char c)
|
|
||||||
{
|
|
||||||
return (c == '#' || c == '0' || c == '-' || c == '+' || c == ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_printf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
int i;
|
|
||||||
char *ret;
|
|
||||||
char flags[4];
|
|
||||||
int dim[2];
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ret = ft_strnew(0);
|
|
||||||
va_start(ap, format);
|
|
||||||
while (format[i])
|
|
||||||
{
|
|
||||||
if (format[i] == '%')
|
|
||||||
{
|
|
||||||
dim[0] = 0;
|
|
||||||
while (dim[0] < 4)
|
|
||||||
flags[dim[0]++] = 0;
|
|
||||||
dim[0] = 0;
|
|
||||||
dim[1] = 0;
|
|
||||||
i++;
|
|
||||||
while (is_flag(format[i]))
|
|
||||||
{
|
|
||||||
if (format[i] == '-')
|
|
||||||
{
|
|
||||||
flags[0] = '-';
|
|
||||||
flags[2] = 0;
|
|
||||||
}
|
|
||||||
else if (format[i] == '+')
|
|
||||||
flags[1] = '+';
|
|
||||||
else if (format[i] == ' ' && flags[1] == 0)
|
|
||||||
flags[1] = ' ';
|
|
||||||
else if (format[i] == '0' && flags[0] == 0)
|
|
||||||
flags[2] = '0';
|
|
||||||
else
|
|
||||||
flags[3] = '#';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dim[0] = ft_atoi(&format[i]);
|
|
||||||
while (ft_isdigit(format[i]))
|
|
||||||
i++;
|
|
||||||
if (format[i] == '.')
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
dim[1] = ft_atoi(&format[i]);
|
|
||||||
}
|
|
||||||
while (ft_isdigit(format[i]))
|
|
||||||
i++;
|
|
||||||
if (format[i] == '%')
|
|
||||||
write(1, "%", 1);
|
|
||||||
else if (format[i] == 'd' || format[i] == 'i')
|
|
||||||
ret = convert_d_i(flags, dim, va_arg(ap, int));
|
|
||||||
write(1, ret, ft_strlen(ret));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
write(1, &format[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_strdel(&ret);
|
|
||||||
va_end(ap);
|
|
||||||
return (0);
|
|
||||||
}
|
|
58
includes/libftprintf.h
Normal file
58
includes/libftprintf.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libftprintf.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/07 13:03:44 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/02/07 17:03:50 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFTPRINTF_H
|
||||||
|
# define LIBFTPRINTF_H
|
||||||
|
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
typedef struct s_flags
|
||||||
|
{
|
||||||
|
enum e_convtype
|
||||||
|
{
|
||||||
|
none = -1,
|
||||||
|
per = '%',
|
||||||
|
c = 'c',
|
||||||
|
s = 's',
|
||||||
|
p = 'p',
|
||||||
|
d = 'd',
|
||||||
|
i = 'i',
|
||||||
|
o = 'o',
|
||||||
|
u = 'u',
|
||||||
|
x = 'x',
|
||||||
|
X = 'X',
|
||||||
|
f = 'f'
|
||||||
|
} convtype;
|
||||||
|
char minus;
|
||||||
|
char sign;
|
||||||
|
char hash;
|
||||||
|
int width;
|
||||||
|
int precision;
|
||||||
|
char size;
|
||||||
|
} t_flags;
|
||||||
|
|
||||||
|
size_t pf_getflags(const char *format, t_flags *flags);
|
||||||
|
|
||||||
|
int pf_convc(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convs(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convp(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convd(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convi(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convo(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convu(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convx(t_flags *flags, va_list *ap);
|
||||||
|
int pf_convf(t_flags *flags, va_list *ap);
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...);
|
||||||
|
|
||||||
|
#endif
|
@@ -5,21 +5,37 @@
|
|||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/05/05 19:19:33 by tmaze #+# #+# */
|
/* Created: 2019/02/07 13:03:44 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/05/05 19:40:06 by tmaze ### ########.fr */
|
/* Updated: 2019/02/07 13:12:20 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef LIBFTPRINTF_H
|
#ifndef LIBFTPRINTF_H
|
||||||
# define LIBFTPRINTF_H
|
# define LIBFTPRINTF_H
|
||||||
|
|
||||||
# include "libft.h"
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <stdarg.h>
|
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <wchar.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
int ft_printf(const char *format, ...);
|
typedef struct s_flags
|
||||||
char *convert_d_i(char *flags, int *dim, int nb);
|
{
|
||||||
|
enum e_convtype
|
||||||
|
{
|
||||||
|
c,
|
||||||
|
s,
|
||||||
|
p,
|
||||||
|
d,
|
||||||
|
i,
|
||||||
|
o,
|
||||||
|
u,
|
||||||
|
x,
|
||||||
|
X,
|
||||||
|
f
|
||||||
|
} convtype;
|
||||||
|
char minus;
|
||||||
|
char sign;
|
||||||
|
int width;
|
||||||
|
int precision;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
133
libft.h
133
libft.h
@@ -1,133 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
|
|
||||||
/* Updated: 2018/05/05 16:49:16 by tmaze ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
|
|
||||||
# include <string.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
** définition type t_list
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
size_t content_size;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
/*
|
|
||||||
** fonctions obligatoires
|
|
||||||
*/
|
|
||||||
|
|
||||||
void *ft_memset(void *b, int c, size_t len);
|
|
||||||
void ft_bzero(void *s, size_t n);
|
|
||||||
void *ft_memcpy(void *dest, const void *src,\
|
|
||||||
size_t n);
|
|
||||||
void *ft_memccpy(void *dest, const void *src,\
|
|
||||||
int c, size_t n);
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t len);
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
char *ft_strdup(const char *s);
|
|
||||||
char *ft_strcpy(char *dest, const char *src);
|
|
||||||
char *ft_strncpy(char *dest, const char *src, size_t n);
|
|
||||||
char *ft_strcat(char *dest, const char *src);
|
|
||||||
char *ft_strncat(char *dest, const char *src,\
|
|
||||||
size_t n);
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
|
||||||
char *ft_strchr(const char *s, int c);
|
|
||||||
char *ft_strrchr(const char *s, int c);
|
|
||||||
char *ft_strstr(const char *haystack, const char *needle);
|
|
||||||
char *ft_strnstr(const char *haystack, const char *needle,\
|
|
||||||
size_t len);
|
|
||||||
int ft_strcmp(const char *s1, const char *s2);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|
||||||
int ft_atoi(const char *str);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isdigit(int c);
|
|
||||||
int ft_isalnum(int c);
|
|
||||||
int ft_isascii(int c);
|
|
||||||
int ft_isprint(int c);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** fonctions supplémentaires
|
|
||||||
*/
|
|
||||||
|
|
||||||
void *ft_memalloc(size_t size);
|
|
||||||
void ft_memdel(void **ap);
|
|
||||||
char *ft_strnew(size_t size);
|
|
||||||
void ft_strdel(char **as);
|
|
||||||
void ft_strclr(char *s);
|
|
||||||
void ft_striter(char *s, void (*f)(char *));
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
|
||||||
char *ft_strmap(char const *s, char (*f)(char));
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
|
||||||
int ft_strequ(char const *s1, char const *s2);
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *ft_strtrim(char const *s);
|
|
||||||
char **ft_strsplit(char const *s, char c);
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_putstr(char const *s);
|
|
||||||
void ft_putendl(char const *s);
|
|
||||||
void ft_putnbr(int n);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char const *s, int fd);
|
|
||||||
void ft_putendl_fd(char const *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** fonctions bonus
|
|
||||||
*/
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
|
||||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
|
||||||
|
|
||||||
/*
|
|
||||||
** fonctions additionneles
|
|
||||||
*/
|
|
||||||
|
|
||||||
int ft_isupper(int c);
|
|
||||||
int ft_islower(int c);
|
|
||||||
int ft_str_is_alpha(char *str);
|
|
||||||
int ft_str_is_lowercase(char *str);
|
|
||||||
int ft_str_is_numeric(char *str);
|
|
||||||
int ft_str_is_printable(char *str);
|
|
||||||
int ft_str_is_uppercase(char *str);
|
|
||||||
char *ft_strlowcase(char *s);
|
|
||||||
char *ft_strupcase(char *s);
|
|
||||||
char *ft_strcapitalize(char *str);
|
|
||||||
size_t ft_strlcpy(char *dst, const char *src,\
|
|
||||||
size_t size);
|
|
||||||
size_t ft_lstsize(t_list *lst);
|
|
||||||
t_list *ft_lstgetat(t_list *lst, size_t ind);
|
|
||||||
t_list *ft_lstgetlast(t_list *lst);
|
|
||||||
void ft_sort_params(int ac, char **av);
|
|
||||||
void ft_print_words_tables(char **tab);
|
|
||||||
t_list *ft_lstaddend(t_list **alst, t_list *new);
|
|
||||||
char *ft_strndup(const char *s1, size_t n);
|
|
||||||
unsigned int ft_abs(int nb);
|
|
||||||
|
|
||||||
#endif
|
|
36
srcs/ft_printf.c
Normal file
36
srcs/ft_printf.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/07 13:31:16 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/02/07 14:21:34 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libftprintf.h"
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
t_flags flags;
|
||||||
|
static int (*convf[10])(t_flags *flags, va_list *ap) = {pf_convc,
|
||||||
|
pf_convs, pf_convp, pf_convd, pf_convi, pf_convo, pf_convu, pf_convx,
|
||||||
|
pf_convx, pf_convf};
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
i = 0;
|
||||||
|
while (format[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (format[i + j] && format[i + j] != '%')
|
||||||
|
j++;
|
||||||
|
write(1, &format[i], j);
|
||||||
|
i += j;
|
||||||
|
j = pf_getflags(&format[i], &flags);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,28 +1,21 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* printf.c :+: :+: :+: */
|
/* ft_printf.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/05/01 15:01:57 by tmaze #+# #+# */
|
/* Created: 2019/02/07 13:31:16 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/05/05 19:37:56 by tmaze ### ########.fr */
|
/* Updated: 2019/02/07 13:34:43 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "libftprintf.h"
|
#include "libftprintf.h"
|
||||||
|
|
||||||
char happy[] = { 0xe2, 0x98, 0xba }; /* U+263A */
|
int ft_printf(const char *format, ...)
|
||||||
wchar_t Whappy[] = { 0xe2, 0x98, 0xba }; /* U+263A */
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
{
|
||||||
write(1, happy, 3);
|
va_list ap;
|
||||||
write(1, "\n", 1);
|
size_t i;
|
||||||
printf("plop %++0 #%plap \"%+-20.10i\"\n", 15);
|
|
||||||
// printf("%lu %#% %S \"% -10.8d\" \"%-10.8s\"\n", sizeof(wchar_t), Whappy, -1475, "Je suis");
|
va_start();
|
||||||
ft_printf("plop %++0 #%plap \"%+-20.10i\"\n", 15);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
60
srcs/pf_getflags.c
Normal file
60
srcs/pf_getflags.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* pf_getflags.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/07 14:14:38 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/02/07 17:11:26 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libftprintf.h"
|
||||||
|
|
||||||
|
void pf_initflags(t_flags *flags)
|
||||||
|
{
|
||||||
|
flags->convtype = none;
|
||||||
|
flags->minus = '\0';
|
||||||
|
flags->sign = '\0';
|
||||||
|
flags->hash = '\0';
|
||||||
|
flags->width = 0;
|
||||||
|
flags->precision = 0;
|
||||||
|
flags->size = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t pf_getflags(const char *format, t_flags *flags)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
pf_initflags(flags);
|
||||||
|
i = 0;
|
||||||
|
while (format[++i] && ft_strchr("%cspdiouxXf", format[i]) != NULL)
|
||||||
|
{
|
||||||
|
if (format[i] == '-')
|
||||||
|
flags->minus = '-';
|
||||||
|
if (format[i] == '#')
|
||||||
|
flags->hash = '#';
|
||||||
|
if (format[i] == ' ' || format[i] == '+')
|
||||||
|
flags->sign = format[i];
|
||||||
|
if (ft_isdigit(format[i])
|
||||||
|
|| (format[i] == '.' && ft_isdigit(format[i + 1])))
|
||||||
|
{
|
||||||
|
if (ft_isdigit(format[i]))
|
||||||
|
flags->width = ft_atoi(&format[i]);
|
||||||
|
else
|
||||||
|
flags->precision = ft_atoi(&format[i + 1]);
|
||||||
|
while (format[i + 1] && ft_isdigit(format[i + 1]))
|
||||||
|
i++;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
if (format[i] == 'h' || format[i] == 'l')
|
||||||
|
{
|
||||||
|
flags->size = format[i];
|
||||||
|
if (format[i + 1] && format[i + 1] == format[i])
|
||||||
|
flags->size = ft_toupper(format[++i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flags->convtype = format[i];
|
||||||
|
return (i);
|
||||||
|
}
|
18
srcs/pf_getflags.c~
Normal file
18
srcs/pf_getflags.c~
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* pf_getflags.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/07 14:14:38 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/02/07 14:20:13 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libftprintf.h"
|
||||||
|
|
||||||
|
size_t *pf_getflags(const char *format, t_flags *flags)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user