debut mise a la norme exec
This commit is contained in:
commit
14ad158646
22 changed files with 165 additions and 134 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:34:20 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 16:07:29 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,10 +21,10 @@
|
||||||
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||||
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||||
|
|
||||||
# define EXEC_AND_IF (1 << 2)
|
# define EXEC_AND_IF (1 << 0)
|
||||||
# define EXEC_OR_IF (1 << 3)
|
# define EXEC_OR_IF (1 << 1)
|
||||||
# define EXEC_IF_BRANCH (1 << 4)
|
# define EXEC_IF_BRANCH (1 << 2)
|
||||||
# define EXEC_CASE_BRANCH (1 << 5)
|
# define EXEC_CASE_BRANCH (1 << 3)
|
||||||
|
|
||||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:17:20 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:39:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ ft_printf/ft_printf.c\
|
||||||
ft_printf/ft_printf_color.c\
|
ft_printf/ft_printf_color.c\
|
||||||
ft_printf/ft_printf_parse.c\
|
ft_printf/ft_printf_parse.c\
|
||||||
ft_printf/ft_transform.c\
|
ft_printf/ft_transform.c\
|
||||||
|
ft_printf/ft_vprintf.c\
|
||||||
ft_printf/lib_fmt.c\
|
ft_printf/lib_fmt.c\
|
||||||
ft_printf/lib_fmt_error.c\
|
ft_printf/lib_fmt_error.c\
|
||||||
ft_printf/lib_pad.c\
|
ft_printf/lib_pad.c\
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 19:00:17 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:48:05 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CLI_OPTS_H
|
#ifndef CLIOPTS_H
|
||||||
# define CLI_OPTS_H
|
# define CLIOPTS_H
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "error.h"
|
# include "error.h"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 14:19:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:48:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,15 +16,15 @@
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
# define DG_PROTO "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
# define DG(s, ...) ft_dprintf(STDBUG, DG_PROTO s "{eoc}\n", DG_ARGS, ##__VA_ARGS__)
|
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
# define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__
|
# define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__
|
||||||
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
||||||
# define ERRMSG_MAX_SIZE 150
|
# define ERRMSG_MAX_SIZE 150
|
||||||
|
|
||||||
enum e_errors
|
enum e_errors
|
||||||
{
|
{
|
||||||
E_NOERR,
|
E_NOERR,
|
||||||
E_CO_INV,
|
E_CO_INV,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
/* ************************************************************************** */ /* */
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* math.h :+: :+: :+: */
|
/* math.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/18 13:19:12 by jhalford #+# #+# */
|
/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/18 13:19:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 09:28:34 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** void *data must be a structure starting with `int flag`
|
** void *data must be a structure starting with `int flag`
|
||||||
** to do polymorphism with t_data_template !
|
** to do polymorphism with t_data_template !
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include "cliopts.h"
|
#include "cliopts.h"
|
||||||
|
|
||||||
static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg)
|
static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg)
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +39,8 @@ static t_cliopts *get_map_short(t_cliopts opt_map[], char arg)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data)
|
static int cliopts_parse_short(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
{
|
{
|
||||||
t_cliopts *map;
|
t_cliopts *map;
|
||||||
char *arg;
|
char *arg;
|
||||||
|
|
@ -67,7 +68,8 @@ static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cliopts_parse_long(char ***av, t_cliopts opt_map[], void *data)
|
static int cliopts_parse_long(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
{
|
{
|
||||||
t_cliopts *map;
|
t_cliopts *map;
|
||||||
char *arg;
|
char *arg;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 20:24:39 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ int cliopts_has(char **av, char c)
|
||||||
{
|
{
|
||||||
if (!av)
|
if (!av)
|
||||||
return (0);
|
return (0);
|
||||||
while (*av)
|
while (*av)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(*av, "--") == 0)
|
if (ft_strcmp(*av, "--") == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/11 13:14:19 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:50:57 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char base10[] = "0123456789";
|
static char base10[] = "0123456789";
|
||||||
long long arg;
|
long long arg;
|
||||||
|
|
||||||
arg = va_arg(ap, int);
|
arg = va_arg(ap, int);
|
||||||
|
|
@ -61,7 +61,7 @@ char *ft_str_conversion(t_fmt *fmt, va_list ap)
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
ret = va_arg(ap, char *);
|
ret = va_arg(ap, char *);
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
return(ft_strdup("NULL"));
|
return (ft_strdup("NULL"));
|
||||||
ret = ft_strdup(ret);
|
ret = ft_strdup(ret);
|
||||||
if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
|
if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
|
||||||
ret[fmt->precision] = '\0';
|
ret[fmt->precision] = '\0';
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,12 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 09:22:14 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 16:10:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_printf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
t_conv g_convs[] =
|
|
||||||
{
|
|
||||||
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
|
||||||
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
|
||||||
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
|
|
||||||
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
|
|
||||||
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'s', "-", "", &ft_str_conversion, NULL},
|
|
||||||
{'c', "-", "", &ft_char_conversion, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
int ft_printf(const char *format, ...)
|
int ft_printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
@ -44,64 +31,7 @@ int ft_dprintf(int fd, const char *format, ...)
|
||||||
int ft_asprintf(char **ret, const char *format, ...)
|
int ft_asprintf(char **ret, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
return (ft_vasprintf(ret, format, ap));
|
return (ft_vasprintf(ret, format, ap));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_vdprintf(int fd, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
|
|
||||||
ret = NULL;
|
|
||||||
if (ft_vasprintf(&ret, format, ap))
|
|
||||||
return (1);
|
|
||||||
ft_putstr_fd(ret, fd);
|
|
||||||
ft_strdel(&ret);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_vasprintf(char **ret, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
char *tmp;
|
|
||||||
char *final;
|
|
||||||
|
|
||||||
str = (char *)format;
|
|
||||||
final = ft_strnew(1);
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
tmp = final;
|
|
||||||
if (*str == '{')
|
|
||||||
ft_printf_color(&final, &str, ap);
|
|
||||||
else if (*str == '%')
|
|
||||||
{
|
|
||||||
if (ft_fmtcalc(&final, &str, ap))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
final = ft_strjoin(final, (char[]){*str++, 0});
|
|
||||||
ft_strdel(&tmp);
|
|
||||||
}
|
|
||||||
*ret = final;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_fmtcalc(char **final, char **str, va_list ap)
|
|
||||||
{
|
|
||||||
t_fmt *fmt;
|
|
||||||
char *transform;
|
|
||||||
|
|
||||||
*str += 1;
|
|
||||||
if (!(fmt = ft_printf_parse(str, ap)))
|
|
||||||
return (1);
|
|
||||||
if (!fmt->valid)
|
|
||||||
ft_strncat(*final, &fmt->conversion, 1);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transform = ft_transform(fmt, ap);
|
|
||||||
*final = ft_strjoin(*final, transform);
|
|
||||||
ft_strdel(&transform);
|
|
||||||
}
|
|
||||||
free(fmt);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/11 14:00:20 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,11 +40,10 @@ void ft_printf_color(char **final, char **str, va_list ap)
|
||||||
*str += 5;
|
*str += 5;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
while(g_colors[i].key)
|
while (g_colors[i].key)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
|
if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
|
||||||
{
|
{
|
||||||
/* if (isatty(fd)) */
|
|
||||||
*final = ft_strjoin(*final, g_colors[i].val);
|
*final = ft_strjoin(*final, g_colors[i].val);
|
||||||
*str += 5;
|
*str += 5;
|
||||||
return ;
|
return ;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 09:17:48 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -121,4 +121,3 @@ t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
||||||
return (fmt);
|
return (fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
84
42sh/libft/src/ft_printf/ft_vprintf.c
Normal file
84
42sh/libft/src/ft_printf/ft_vprintf.c
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_vprintf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:53:17 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_conv g_convs[] =
|
||||||
|
{
|
||||||
|
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
|
||||||
|
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
|
||||||
|
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'s', "-", "", &ft_str_conversion, NULL},
|
||||||
|
{'c', "-", "", &ft_char_conversion, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
ret = NULL;
|
||||||
|
if (ft_vasprintf(&ret, format, ap))
|
||||||
|
return (1);
|
||||||
|
ft_putstr_fd(ret, fd);
|
||||||
|
ft_strdel(&ret);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_vasprintf(char **ret, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *tmp;
|
||||||
|
char *final;
|
||||||
|
|
||||||
|
str = (char *)format;
|
||||||
|
final = ft_strnew(1);
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
tmp = final;
|
||||||
|
if (*str == '{')
|
||||||
|
ft_printf_color(&final, &str, ap);
|
||||||
|
else if (*str == '%')
|
||||||
|
{
|
||||||
|
if (ft_fmtcalc(&final, &str, ap))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
final = ft_strjoin(final, (char[]){*str++, 0});
|
||||||
|
ft_strdel(&tmp);
|
||||||
|
}
|
||||||
|
*ret = final;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_fmtcalc(char **final, char **str, va_list ap)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
char *transform;
|
||||||
|
|
||||||
|
*str += 1;
|
||||||
|
if (!(fmt = ft_printf_parse(str, ap)))
|
||||||
|
return (1);
|
||||||
|
if (!fmt->valid)
|
||||||
|
ft_strncat(*final, &fmt->conversion, 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transform = ft_transform(fmt, ap);
|
||||||
|
*final = ft_strjoin(*final, transform);
|
||||||
|
ft_strdel(&transform);
|
||||||
|
}
|
||||||
|
free(fmt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */
|
/* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,8 +24,11 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
||||||
|
|
||||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
||||||
{
|
{
|
||||||
char start[3] = {'0',fmt->conversion, 0};
|
char start[3];
|
||||||
|
|
||||||
|
start[0] = '0';
|
||||||
|
start[1] = fmt->conversion;
|
||||||
|
start[2] = 0;
|
||||||
if (str[0] == '0')
|
if (str[0] == '0')
|
||||||
{
|
{
|
||||||
if (str[1] == '0')
|
if (str[1] == '0')
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */
|
/* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/03 16:12:40 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:55:29 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
char *ft_strdupi_w(char const *s)
|
char *ft_strdupi_w(char const *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcspn.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:55:33 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 16:00:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
size_t ft_strcspn(char *s, const char *delim)
|
size_t ft_strcspn(char *s, const char *delim)
|
||||||
|
|
@ -5,8 +17,8 @@ size_t ft_strcspn(char *s, const char *delim)
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
str = s;
|
str = s;
|
||||||
while(*str)
|
while (*str)
|
||||||
if(ft_strchr(delim,*str))
|
if (ft_strchr(delim, *str))
|
||||||
return (str - s);
|
return (str - s);
|
||||||
else
|
else
|
||||||
str++;
|
str++;
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/02 15:11:28 by ariard #+# #+# */
|
/* Created: 2017/03/02 15:11:28 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/07 11:44:29 by ariard ### ########.fr */
|
/* Updated: 2017/03/20 16:01:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
int ft_stris(char *str, int (*f)())
|
int ft_stris(char *str, int (*f)())
|
||||||
{
|
{
|
||||||
while (*str)
|
while (*str)
|
||||||
if (!(f)(*str++))
|
if (!(f)(*str++))
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 16:10:24 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static int ft_countwords(char const *s, char c)
|
static int ft_countwords(char const *s, char c)
|
||||||
{
|
{
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
return ((*s == '\0') ? 0 : 1);
|
return ((*s == '\0') ? 0 : 1);
|
||||||
|
|
@ -36,9 +36,9 @@ static int get_word_len(char const *str, char c)
|
||||||
i++;
|
i++;
|
||||||
while (str[i] != c && str[i] != '\0')
|
while (str[i] != c && str[i] != '\0')
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
return (len);
|
return (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,21 +50,21 @@ char **ft_strsplit(char const *s, char c)
|
||||||
char **str2;
|
char **str2;
|
||||||
|
|
||||||
if (!s || !(str2 = (char **)malloc(sizeof(*str2) *
|
if (!s || !(str2 = (char **)malloc(sizeof(*str2) *
|
||||||
(ft_countwords(s, c) + 1))))
|
(ft_countwords(s, c) + 1))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i = -1;
|
i = -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
while (++i < ft_countwords(s, c))
|
while (++i < ft_countwords(s, c))
|
||||||
{
|
{
|
||||||
k = 0;
|
k = 0;
|
||||||
if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1)))
|
if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1)))
|
||||||
str2[i] = NULL;
|
str2[i] = NULL;
|
||||||
while (s[j] == c)
|
while (s[j] == c)
|
||||||
j++;
|
j++;
|
||||||
while (s[j] != c && s[j])
|
while (s[j] != c && s[j])
|
||||||
str2[i][k++] = s[j++];
|
str2[i][k++] = s[j++];
|
||||||
str2[i][k] = '\0';
|
str2[i][k] = '\0';
|
||||||
}
|
}
|
||||||
str2[i] = 0;
|
str2[i] = 0;
|
||||||
return (str2);
|
return (str2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
|
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:51:07 by gwojda ### ########.fr */
|
/* Updated: 2017/03/20 16:28:33 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */
|
/* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 14:07:42 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:39:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:55:53 by wescande #+# #+# */
|
/* Created: 2017/03/07 15:55:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/20 10:24:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 15:36:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/16 17:56:16 by ariard ### ########.fr */
|
/* Updated: 2017/03/20 15:39:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue