Beispiel #1
0
char		*ft_itoa(int n)
{
	int		count;
	int		signe;
	char	*result;

	count = ft_intlen(n);
	signe = 1;
	if (!n)
		return (ft_strdup("0"));
	if (n < 0)
	{
		signe = -1;
		result = (char *)malloc(sizeof(char) * ft_intlen(n) + 2);
		count++;
		result[0] = '-';
	}
	else
		result = (char *)malloc(sizeof(char) * ft_intlen(n) + 1);
	result[count] = '\0';
	while (n != 0)
	{
		result[count - 1] = (n % 10) * signe + 48;
		n = n / 10;
		count--;
	}
	return (result);
}
Beispiel #2
0
void	ft_link(t_dir *file, t_len len, size_t i)
{
	if (S_ISBLK(file->buf.st_mode) || S_ISCHR(file->buf.st_mode))
	{
		while (i++ < 5 - ft_intlen(major(file->buf.st_rdev)))
			ft_putchar(' ');
		ft_putnbr(major(file->buf.st_rdev));
		ft_putchar(',');
		i = 0;
		while (i++ < 4 - ft_intlen(minor(file->buf.st_rdev)))
			ft_putchar(' ');
		ft_putnbr(minor(file->buf.st_rdev));
	}
	else
	{
		if (len.dev)
		{
			while (i++ < len.maj_min - ft_intlen(file->buf.st_size) + 1)
				ft_putchar(' ');
		}
		else
		{
			while (i++ < len.size - ft_intlen(file->buf.st_size) + 2)
				ft_putchar(' ');
		}
		ft_putnbr(file->buf.st_size);
	}
}
Beispiel #3
0
void		print_ischr(t_file *dir, t_align *max_all)
{
	int sn;

	sn = 0;
	if (ft_intlen(major(dir->stat->st_rdev)) < max_all->major)
	{
		sn = max_all->major - ft_intlen(major(dir->stat->st_rdev));
		while (sn-- != 0)
			ft_putchar(' ');
		ft_putnbr(major(dir->stat->st_rdev));
	}
	else
		ft_putnbr(major(dir->stat->st_rdev));
	ft_putstr(", ");
	if (ft_intlen(minor(dir->stat->st_rdev)) < max_all->minor)
	{
		sn = max_all->minor - ft_intlen(minor(dir->stat->st_rdev));
		while (sn-- != 0)
			ft_putchar(' ');
		ft_putnbr(minor(dir->stat->st_rdev));
	}
	else
		ft_putnbr(minor(dir->stat->st_rdev));
	ft_putchar(' ');
}
Beispiel #4
0
void				maj_env(t_ls_entry e)
{
	size_t			size;

	if (!e.handle && !IS(O_HIDE, env()->o))
		return ;
	if ((size = ft_intlen(e.stat.st_nlink)) > env()->nlinkpad)
		env()->nlinkpad = size;
	if ((size = ft_intlen(e.stat.st_size)) > env()->sizepad)
		env()->sizepad = size;
	if ((size = ft_strlen(getpwuid(e.stat.st_uid)->pw_name)) > env()->ownerlen)
		env()->ownerlen = size;
	if ((size = ft_strlen(getgrgid(e.stat.st_gid)->gr_name)) > env()->grplen)
		env()->grplen = size;
}
Beispiel #5
0
char		*ft_itoa(int n)
{
	int		i;
	int		neg;
	char	*str;

	i = 0;
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	check_neg(&n, &neg);
	if ((str = ft_alloc(ft_intlen(n), neg)) == NULL)
		return (NULL);
	while (n > 9)
	{
		str[i] = ((n % 10) + '0');
		ft_fuck_norminette(&n, &i);
	}
	str[i] = n + '0';
	i++;
	if (neg == 1)
	{
		str[i] = '-';
		i++;
	}
	str[i] = '\0';
	ft_swap(str);
	return (str);
}
Beispiel #6
0
char	*ft_itoa(int n)
{
	int		i;
	char	*str;
	int		div;

	i = 0;
	div = 1;
	str = (char *)malloc(sizeof(char) * ft_intlen(n) + 1);
	if (n == -2147483648)
		return ("-2147483648");
	else if (n < 0)
	{
		str[i++] = '-';
		n = -n;
	}
	while (n / div > 9)
		div *= 10;
	while (div != 0)
	{
		str[i++] = (n / div) + 48;
		n %= div;
		div /= 10;
	}
	str[i] = '\0';
	return (str);
}
Beispiel #7
0
void	ft_check_file(char *buf)
{
	int		i;
	char	*str;
	t_param *tmp_param;

	i = 0;
	str = first_line(buf);
	tmp_param = ft_get_parameters(buf);
	if (str[0] >= 48 && str[0] <= 57)
	{
		str[ft_strlen_mod(buf) - 3] = '\0';
		if (ft_atoi(str) != size_col(buf))
			ft_error();
		i = ft_intlen(ft_atoi(str));
		str = first_line(buf);
		if (str[i] == tmp_param->empty)
			i++;
		if (str[i] == tmp_param->obst)
			i++;
		if (str[i] == tmp_param->full)
			i++;
		else
			ft_error();
	}
	else
		ft_error();
}
Beispiel #8
0
char	*ft_itoa(int n)
{
	int		i;
	char	*str;
	int		div;

	i = 0;
	div = 1;
	if (n == -2147483648)
	{
		str = (char *)malloc(sizeof(char) * 12);
		ft_strcpy(str, "-2147483648");
		return (str);
	}
	str = (char *)malloc(sizeof(char) * ft_intlen(n) + 1);
	if (!str)
		return (NULL);
	if (n < 0)
	{
		str[i++] = '-';
		n *= -1;
	}
	str = ft_tobecontinued(str, n, &i, div);
	str[i] = '\0';
	return (str);
}
Beispiel #9
0
char		*ft_itoa(int n)
{
	char	*s;
	int		i;
	int		tmp;
	int		j;

	i = 0;
	j = 0;
	if ((s = ft_test_spec(n)))
		return (s);
	if ((s = (char *)malloc(sizeof(char) * ft_intlen(n))) == NULL)
		return (0);
	if (n < 0)
	{
		j++;
		n = n * -1;
	}
	while (n != 0)
	{
		tmp = n % 10;
		s[i++] = tmp + '0';
		n = n / 10;
	}
	s[i] = '\0';
	return (ft_reverse(s, j));
}
Beispiel #10
0
char			*ft_itoa(int n)
{
	char		*str;
	char		c;
	int			i;
	size_t		len;

	i = 0;
	len = ft_intlen(n);
	str = ft_strnew(len + 1);
	if (n == 0)
		str[0] = '0';
	else if (n < 0)
		str[len - 1] = '-';
	while (n)
	{
		if (n < 0)
			c = (n % 10) * -1 + '0';
		else
			c = n % 10 + '0';
		n = n / 10;
		str[i] = c;
		i++;
	}
	str = ft_strreverse(str);
	str[len] = '\0';
	return (str);
}
Beispiel #11
0
void	ft_print_long(t_dir *file, t_len len, t_option *op, size_t u)
{
	size_t		i;

	i = 0;
	ft_mode(file->absolute, file->buf.st_mode);
	while (i++ < len.links - ft_intlen(file->buf.st_nlink))
		ft_putchar(' ');
	ft_putnbr(file->buf.st_nlink);
	ft_putchar(' ');
	ft_putstr(file->format->uid_name);
	i = 0;
	while (i++ < len.uid - ft_strlen(file->format->uid_name) + u)
		ft_putchar(' ');
	ft_putstr(file->format->gid_name);
	i = 0;
	while (i++ < len.gid - ft_strlen(file->format->gid_name))
		ft_putchar(' ');
	ft_link(file, len, 0);
	if (op->long_date == 1)
		write(1, file->format->time + 3, 21);
	else
		ft_date(file, op);
	ft_putchar(' ');
}
Beispiel #12
0
char	*ft_itoa(int n)
{
	char			*str;
	int				i;
	unsigned int	nb;
	int				len;

	len = ft_intlen(n);
	i = 0;
	nb = (unsigned int)n;
	str = ft_strnew(len);
	if (!str)
		return (NULL);
	if (n < 0)
	{
		nb = -n;
		str[0] = '-';
	}
	str[len] = '\0';
	if (n == 0)
		str[--len] = '0';
	while (nb != 0)
	{
		str[--len] = (nb % 10) + 48;
		nb = nb / 10;
	}
	return (str);
}
Beispiel #13
0
void	ft_itoa_printf(intmax_t n, t_printf *buf)
{
	int			len;
	int			neg;
	char		tab[25];
	int			tmp;

	if (n == -9223372036854775807 - 1)
		return (ft_strcat_printf(&buf->buf, "-9223372036854775808"));
	len = ft_intlen(n) + 1;
	neg = (n < 0) ? 1 : 0;
	len += (n < 0) ? 1 : 0;
	n = (n < 0) ? n *= -1 : n;
	tab[--len] = '\0';
	tmp = len;
	if (buf->minus == 0)
		ft_fill_width_precision(buf, len);
	while (len--)
	{
		tab[len] = n % 10 + '0';
		n = n / 10;
	}
	if (neg)
		tab[0] = '-';
	ft_strcat_printf(&buf->buf, tab);
	if (buf->minus == 1)
		ft_fill_width_precision(buf, tmp);
}
Beispiel #14
0
char			*ft_itoa(int n)
{
	char	*ret;
	int		len;

	if (n == -2147483648)
		return (ret = "-2147483648");
	if (n >= 0)
		len = ft_intlen(n);
	if (n < 0)
		len = ft_intlenneg(n);
	if ((ret = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
		return (NULL);
	len--;
	if (n < 0)
	{
		ret[0] = '-';
		n = -n;
	}
	while (n >= 10)
	{
		ret[len] = ((n % 10) + 48);
		n = n / 10;
		len--;
	}
	ret[len] = (n + 48);
	return (ret);
}
Beispiel #15
0
char				*ft_itoa(int i)
{
	char	*s;
	int		j;
	int		temp;
	int		len;

	if (i == -2147483648)
		return ("-2147483648");
	j = 0;
	len = ft_intlen(i);
	s = (char*)malloc(sizeof(char) * len);
	if (i < 0)
	{
		s[j++] = '-';
		i = i * -1;
		len--;
	}
	while (len - 1)
	{
		temp = i / ft_pow(10, len - 2);
		s[j++] = temp + 48;
		i = i - temp * ft_pow(10, len - 2);
		len--;
	}
	s[j] = '\0';
	return (s);
}
Beispiel #16
0
char	*ft_itoa(int n)
{
	char	*nb;
	int		len;
	int		sign;

	len = 0;
	sign = 0;
	if (n < 0)
	{
		len = 1;
		sign = 1;
	}
	len += ft_intlen(n);
	nb = (char*)malloc(sizeof(char) * len + 1);
	if (sign == 1)
		nb[0] = '-';
	nb[len] = '\0';
	while (len-- > sign)
	{
		if (n < 0)
			nb[len] = n % 10 * -1 + 48;
		else
			nb[len] = n % 10 + 48;
		n = n / 10;
	}
	return (nb);
}
Beispiel #17
0
char				*ft_llitoa(long long int n)
{
	char				*str;
	unsigned int		len;
	unsigned int		memlen;
	unsigned int		bound;

	len = ft_intlen(n);
	if (n < 0)
		len++;
	if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
		return (NULL);
	bound = 0;
	if (n < 0)
	{
		str[0] = '-';
		bound = 1;
	}
	memlen = len;
	while (len > bound)
	{
		str[len-- - 1] = ((n < 0) ? (-1 * (n % 10)) + '0' : (n % 10) + '0');
		n /= 10;
	}
	str[memlen] = '\0';
	return (str);
}
Beispiel #18
0
void			display_case_nb(t_all *all, t_pos p, int i, int j)
{
	choose_color_case(all, all->map.tab[i][j]);
	fill_square(all, p.x - all->env.size.x / 2 + 1,
		p.y - all->env.size.y / 2 + 1);
	attron(A_UNDERLINE);
	if (all->map.tab[i][j])
	{
		mvprintw(p.y, (p.x - ft_intlen(all->map.tab[i][j])), "%d",
			all->map.tab[i][j]);
	}
	attroff(A_UNDERLINE | COLOR_PAIR(all->env.color_pair));
}
Beispiel #19
0
static char						*ft_core(unsigned long long n, char *str)
{
	unsigned long long			len;

	len = ft_intlen(n);
	str[len] = '\0';
	while (n != 0)
	{
		str[--len] = n % 10 + 48;
		n = n / 10;
	}
	return (str);
}
Beispiel #20
0
char							*ft_ullitoa(unsigned long long nb)
{
	char						*str;
	unsigned long long			i;
	unsigned long long			n;

	if ((str = (char *)malloc(ft_intlen(nb) + 1 * (sizeof(char)))) == NULL)
		return (NULL);
	i = 0;
	n = nb;
	if (n == 0)
	{
		str[0] = '0';
		str[1] = '\0';
		return (str);
	}
	return (ft_core(n, str));
}
Beispiel #21
0
char			*ft_uitoa(unsigned int n)
{
	char			*str;
	unsigned int	len;
	int				memlen;

	len = ft_intlen(n);
	if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
		return (NULL);
	memlen = len;
	while (len > 0)
	{
		str[len-- - 1] = (n % 10) + '0';
		n /= 10;
	}
	str[memlen] = '\0';
	return (str);
}
Beispiel #22
0
void		get_width(const char *format, t_format *formatv, int *i, va_list ap)
{
	int		res;

	if (format[*i] >= '1' && format[*i] <= '9')
	{
		res = ft_atoi(format + *i);
		*i += ft_intlen(res);
		formatv->width = res;
	}
	else if (format[*i] == '*')
	{
		(*i)++;
		formatv->width = va_arg(ap, int);
		if (formatv->width < 0)
		{
			formatv->minus_flag = 1;
			formatv->width = -formatv->width;
		}
	}
Beispiel #23
0
void		ft_uitoa_printf(uintmax_t n, t_printf *buf)
{
	int			len;
	char		tab[25];
	int			tmp;

	len = ft_intlen(n) + 1;
	tab[--len] = '\0';
	tmp = len;
	if (buf->minus == 0)
		ft_fill_width_precision(buf, len);
	while (len--)
	{
		tab[len] = n % 10 + '0';
		n = n / 10;
	}
	ft_strcat_printf(&buf->buf, tab);
	if (buf->minus == 1)
		ft_fill_width_precision(buf, tmp);
}
Beispiel #24
0
char		*ft_itoa(int n)
{
	char	*str;
	size_t	len_str;
	t_bool	neg_val;

	len_str = ft_intlen(n);
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	if ((neg_val = n < 0))
		len_str++;
	if (!(str = ft_strnew(len_str)))
		return (NULL);
	if (neg_val)
	{
		str[0] = '-';
		n *= -1;
	}
	ft_itoa_loc(str + neg_val, n, len_str - 1 - neg_val);
	return (str);
}
Beispiel #25
0
char	*ft_itoa(int n)
{
	int  x;
	char *rpce;

	rpce = ft_strnew(ft_intlen(n));
	if (n < 0)
	{
		*rpce = '-';
		n = n * (-1);
		rpce++;
	}
	x = n % 10;
	if (n > 9)
	{
		rpce = ft_strjoin(rpce, ft_itoa((n - x) / 10));
		*rpce = '0' + x;
	}
	else
		*rpce = '0' + n;

	return (rpce);
}
Beispiel #26
0
char	*ft_itoa(int n)
{
	int		i;
	long	j;
	char	*str;

	i = ft_intlen(n);
	if (!(str = ft_strnew(i)))
		return (NULL);
	j = n;
	if (n < 0)
		j = -j;
	str[i--] = '\0';
	while (i >= 0 && str[i] != '-')
	{
		str[i] = (j % 10) + 48;
		j = j / 10;
		i--;
	}
	if (n < 0)
		str[0] = '-';
	return (str);
}
Beispiel #27
0
static void	gm_put_tab_to_window(int *tab, int j, int tmpx)
{
	int i;

	i = 0;
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_YELLOW, COLOR_BLACK);
	init_pair(4, COLOR_BLUE, COLOR_BLACK);
	init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(6, COLOR_CYAN, COLOR_BLACK);
	init_pair(7, COLOR_WHITE, COLOR_BLACK);
	while (i < 4)
	{
		if (tab[i] != 0)
		{
			attron(COLOR_PAIR(ft_depow2(tab[i]) % 7 + 1));
			mvprintw(j, tmpx * i + tmpx / 2 - ft_intlen(tab[i]) / 2 + 1,
					"%i", tab[i]);
			attroff(COLOR_PAIR(ft_depow2(tab[i]) % 7 + 1));
		}
		i++;
	}
}
Beispiel #28
0
int					check_prec(const char *format, int *i, t_arg *sarg)
{
	int		numb;
	char	*str;

	numb = 0;
	sarg->prec.pt = 1;
	str = ft_strsub(format, *i + 1, ft_strlen(format) - *i - 1);
	if ((numb = ft_atoi(str)) >= 0)
	{
		sarg->prec.n = numb;
		if (numb > 0 || (numb == 0 && str[0] == '0'))
			*i = *i + ft_intlen(numb) + 1;
		else
			*i = *i + 1;
	}
	else
	{
		sarg->prec.n = 0;
		*i = *i + 1;
	}
	ft_strdel(&str);
	return (1);
}
Beispiel #29
0
char			*ft_itoa(intmax_t n)
{
	int			len;
	char		*str;
	int			neg;

	if (n == -9223372036854775807 - 1)
		return (ft_strdup("-9223372036854775808"));
	len = ft_intlen(n) + 1;
	neg = (n < 0) ? 1 : 0;
	len += (n < 0) ? 1 : 0;
	n = (n < 0) ? n *= -1 : n;
	if (!(str = (char *)malloc(sizeof(char) * (len))))
		return (NULL);
	str[--len] = '\0';
	while (len--)
	{
		str[len] = n % 10 + '0';
		n = n / 10;
	}
	if (neg)
		str[0] = '-';
	return (str);
}
Beispiel #30
0
char			*ft_itoa_l(long long n)
{
	char		*str;
	size_t		size;

	size = ft_intlen(n);
	if (!(str = (char*)malloc(sizeof(char) * (size + 1))))
		return (NULL);
	if (!n)
		*str = '0';
	else if (n < -9223372036854775807)
		return (ft_strdup("-9223372036854775808"));
	else if (n == 9223372036854775807)
		return (ft_strdup("9223372036854775807"));
	if (n < 0)
	{
		*str = '-';
		ft_intrev(-1 * n, str + size - 1);
	}
	else
		ft_intrev(n, str + size - 1);
	*(str + size) = '\0';
	return (str);
}