printf reallocation for 0x and 0b prefixes
This commit is contained in:
parent
a39317f43f
commit
44cafa4811
12 changed files with 37 additions and 36 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 18:30:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 18:00:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/07 17:14:27 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:14:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/07 13:48:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 18:03:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/10 12:59:50 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 15:48:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 17:56:37 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:13:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,6 +24,8 @@ char *ft_transform(t_fmt *fmt, va_list ap)
|
|||
ret = (*fmt->conv.converter)(fmt, ap);
|
||||
if (fmt->width > (int)ft_strlen(ret))
|
||||
ret = ft_realloc(ret, fmt->width + 5);
|
||||
else
|
||||
ret = ft_realloc(ret, ft_strlen(ret) + 3);
|
||||
if (ft_strchr(fmt->flags, '-'))
|
||||
ft_pad_right(ret, fmt);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 18:13:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:14:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 17:56:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:07:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,17 +24,20 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
|||
|
||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
||||
{
|
||||
char buf[100];
|
||||
char start[3] = {'0',fmt->conversion, 0};
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
ft_bzero(buf, 100);
|
||||
ft_strcpy(buf, "0");
|
||||
ft_strcat(buf, &fmt->conversion);
|
||||
if (*str == '0')
|
||||
i++;
|
||||
if (*str == '0')
|
||||
i++;
|
||||
ft_strcat(buf, str + i);
|
||||
ft_strcpy(str, buf);
|
||||
if (str[0] == '0')
|
||||
{
|
||||
if (str[1] == '0')
|
||||
str[1] = fmt->conversion;
|
||||
else
|
||||
{
|
||||
str[0] = fmt->conversion;
|
||||
ft_strcatf(str, "0");
|
||||
}
|
||||
}
|
||||
else
|
||||
ft_strcatf(str, start);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 17:56:17 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 18:31:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/07 16:29:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:14:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,7 +20,6 @@ char **ft_sstrdup(char **list)
|
|||
|
||||
i = 0;
|
||||
size = 0;
|
||||
DG("sstrdup call now");
|
||||
while (list[size])
|
||||
size++;
|
||||
cpy = (char **)malloc(sizeof(char *) * (size + 1));
|
||||
|
|
@ -29,7 +28,6 @@ char **ft_sstrdup(char **list)
|
|||
cpy[i++] = ft_strdup(*list);
|
||||
list++;
|
||||
}
|
||||
DG("sstrdup i=%i, size=%i (should be equal)", i, size);
|
||||
cpy[i] = NULL;
|
||||
return (cpy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/10 12:18:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:11:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,16 +14,13 @@
|
|||
|
||||
char *ft_strcat(char *s1, const char *s2)
|
||||
{
|
||||
size_t size;
|
||||
size_t j;
|
||||
char *start;
|
||||
|
||||
size = ft_strlen(s1);
|
||||
j = 0;
|
||||
while (s2 && s2[j])
|
||||
{
|
||||
s1[size + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
s1[size + j] = '\0';
|
||||
return (s1);
|
||||
start = s1;
|
||||
s1 += ft_strlen(s1);
|
||||
if (s2)
|
||||
while (*s2)
|
||||
*s1++ = *s2++;
|
||||
*s1 = 0;
|
||||
return (start);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 17:58:02 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:02:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/05 14:24:31 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/09 19:11:15 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,7 +16,8 @@ char *ft_strjoin(char const *s1, char const *s2)
|
|||
{
|
||||
char *join;
|
||||
|
||||
join = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1);
|
||||
if (!(join = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1)))
|
||||
return (NULL);
|
||||
if (s1)
|
||||
ft_strcpy(join, s1);
|
||||
if (s2)
|
||||
|
|
|
|||
Loading…
Reference in a new issue