コード例 #1
0
void	ft_cut_init_o_short(t_cut *t_v, t_var **var, char **str, int count[3])
{
	(*t_v).k = 0;
	(*t_v).c = 't';
	(*t_v).nbr = ft_nbrlen(var[count[2]]->u_short);
	(*t_v).flag = check_flag(str, count, &(*t_v).nbr, &(*t_v).c);
	(*t_v).l = ft_atoi_spec_o(str[count[0]]);
	str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_short, "01234567");
	(*t_v).nbr = ft_strlen(str[count[0]]);
}
コード例 #2
0
void    ft_cut_init_u_llong(t_cut *t_v, t_var **var, char **str, int count[3])
{
	(*t_v).k = 0;
	(*t_v).c = 't';
	(*t_v).neg = 0;
	(*t_v).nbr = ft_nbrlen_ll(var[count[2]]->u_l_long);
	(*t_v).flag = check_flag(str, count, &(*t_v).nbr, &(*t_v).c);
	(*t_v).check = ft_atoi_ultra(str[count[0]]);
	if (str[count[0]][0] == '.')
		(*t_v).nbr--;
	str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_l_long, "0123456789");
	(*t_v).s_nbr = ft_strlen(str[count[0]]);
}
コード例 #3
0
void    ft_cut_init_x_maj(t_cut *t_v, t_var **var, char **str, int count[3])
{
	(*t_v).k = 0;
	(*t_v).diff = 0;
	(*t_v).p = 0;
	(*t_v).c = 't';
	(*t_v).nbr = ft_nbrlen(var[count[2]]->u_long);
	(*t_v).c_d = ft_atoi_double(str[count[0]]);
	(*t_v).check = ft_atoi_ultra(str[count[0]]);
	(*t_v).flag = check_flag(str, count, &(*t_v).nbr, &(*t_v).c);
	str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_long, "0123456789ABCDEF");
	(*t_v).nbr = ft_strlen(str[count[0]]);
}
コード例 #4
0
void	ft_cut_init_u_char(t_cut *t_v, t_var **var, char **str, int count[3])
{
	(*t_v).k = 0;
	(*t_v).c = 't';
	(*t_v).neg = 0;
	(*t_v).nbr = ft_nbrlen(var[count[2]]->u_carac);
	(*t_v).flag = check_flag(str, count, &(*t_v).nbr, &(*t_v).c);
	(*t_v).check = ft_atoi_ultra(str[count[0]]);
	if (str[count[0]][0] == '.')
		(*t_v).nbr--;
	str[count[0]] = (char *)malloc(sizeof(char) * ((*t_v).nbr * 5));
	str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_carac, "0123456789");
	(*t_v).s_nbr = ft_strlen(str[count[0]]);
}
コード例 #5
0
void	ft_cut_flag_p1(t_cut *t_v, t_var **var, char **str, int count[3])
{
	str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_long, "0123456789abcdef");
	if ((*t_v).check > (*t_v).c_d)
		str[count[0]] = ft_strjoin("0x", str[count[0]]);
	(*t_v).nbr = ft_strlen(str[count[0]]);
	if ((*t_v).c_d >= (*t_v).nbr)
		(*t_v).diff = (*t_v).c_d;
	else
		(*t_v).diff = (*t_v).nbr;
	if (var[count[2]]->entier < 0)
		ft_cut_flag_p1_1(t_v, var, str, count);
	else
		ft_cut_flag_p1_2(t_v, str, count);
	if ((*t_v).check <= (*t_v).c_d)
		str[count[0]] = ft_strjoin("0x", str[count[0]]);
}
コード例 #6
0
void	attrib_x_maj_short(char **str, t_var **var, int count[3])
{
    int nbr;
    int flag;
    int k;
    int l;
    char c;

    k = 0;
    c = 't';
    nbr = ft_nbrlen(var[count[2]]->u_short);
    l = ft_atoi_spec_o(str[count[0]]);
    flag = check_flag(str, count, &nbr, &c);
    str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_short, "0123456789ABCDEF");
    nbr = ft_strlen(str[count[0]]);
    if (flag == 1000)
        str[count[0]] = ft_strjoin("+", str[count[0]]);
    else if (flag == 2000)
        str[count[0]] = ft_strjoin(" ", str[count[0]]);
    else if (flag == 5000)
    {
        str[count[0]] = ft_strjoin("0x", str[count[0]]);
        flag = l;
        nbr++;
    }
    else if (flag == 3000)
    {
        if (var[count[2]]->stars < 0)
        {
            while (k > var[count[2]]->stars + nbr - 1)
            {
                str[count[0]] = ft_strjoin(str[count[0]], " ");
                k--;
            }
        }
        else
        {
            while (k < var[count[2]]->stars - nbr + 1)
            {
                str[count[0]] = ft_strjoin(" ", str[count[0]]);
                k++;
            }
        }
    }
    if (flag != -1 && flag != 1000 && flag != 2000 &&
            flag != 3000 && flag != 5000)
    {
        if (flag < -1 && c != '0')
        {
            while (k > flag + nbr)
            {
                str[count[0]] = ft_strjoin(str[count[0]], " ");
                k--;
            }
        }
        else if (flag > 0 && (c == '0' || c == '.'))
        {
            while (k < flag - nbr)
            {
                str[count[0]] = ft_strjoin("0", str[count[0]]);
                k++;
            }
        }
        else if (flag < -1 && c == '0')
        {
            while (k > flag)
            {
                str[count[0]] = ft_strjoin("0", str[count[0]]);
                k--;
            }
        }
        else
        {
            while (k < flag - nbr)
            {
                str[count[0]] = ft_strjoin(" ", str[count[0]]);
                k++;
            }
        }
    }
    if (c != '.' && c != '0')
    {
        while (str[count[0]][0] == '0' && str[count[0]][1] != '\0')
            str[count[0]] = ft_strsub(str[count[0]], 1, ft_strlen(str[count[0]]));
    }
    count[2]++;
}
コード例 #7
0
void	attrib_u_char(char **str, t_var **var, int count[3])
{
    int nbr;
    int s_nbr;
    int flag;
    char c;
    int k;
    int check;
    int neg;

    k = 0;
    c = 't';
    neg = 0;
    nbr = ft_nbrlen(var[count[2]]->u_carac);
    flag = check_flag(str, count, &nbr, &c);
    check = ft_atoi_ultra(str[count[0]]);
    if (str[count[0]][0] == '.')
        nbr--;
    str[count[0]] = (char *)malloc(sizeof(char) * (nbr * 5));
    str[count[0]] = ft_ntoa_base_un(var[count[2]]->u_carac, "0123456789");
    s_nbr = ft_strlen(str[count[0]]);
    if (flag == 1000)
    {
        neg = 1;
        str[count[0]] = ft_strjoin("+", str[count[0]]);
    }
    else if (flag == 2000)
        str[count[0]] = ft_strjoin(" ", str[count[0]]);
    else if (flag == 4000)
    {
        str[count[0]] = ft_strjoin("+", str[count[0]]);
        while (k < check - s_nbr)
        {
            str[count[0]] = ft_strjoin(str[count[0]], " ");
            k++;
        }
    }
    else if (flag == 3000)
    {
        if (var[count[2]]->stars < 0)
        {
            while (k > var[count[2]]->stars + nbr - 1)
            {
                str[count[0]] = ft_strjoin(str[count[0]], " ");
                k--;
            }
        }
        else
        {
            while (k < var[count[2]]->stars - nbr + 1)
            {
                str[count[0]] = ft_strjoin(" ", str[count[0]]);
                k++;
            }
        }
    }
    else if (flag != 1 && flag != 1000 && flag != 2000 &&
             flag != 3000 && flag != 5000)
    {
        if (flag < -1 && c != '0')
        {
            while (k > flag + s_nbr + neg)
            {
                str[count[0]] = ft_strjoin(str[count[0]], " ");
                k--;
            }
        }
        else if (flag > 0 && (c == '0' || c == '.'))
        {
            while (k < flag - s_nbr - neg)
            {
                str[count[0]] = ft_strjoin("0", str[count[0]]);
                k++;
            }
        }
        else if (flag < -1 && c == '0')
        {
            while (k > flag)
            {
                str[count[0]] = ft_strjoin("0", str[count[0]]);
                k--;
            }
        }
        else
        {
            while (k < flag - s_nbr - neg)
            {
                str[count[0]] = ft_strjoin(" ", str[count[0]]);
                k++;
            }
        }
    }
    count[2]++;
}
コード例 #8
0
ファイル: ft_putlong.c プロジェクト: dbousque/corewar
int		ft_putlonglong_un(unsigned long long value, char **str)
{
	if ((*str = ft_ntoa_base_un(value, "0123456789")))
		return (ft_strlen(*str));
	return (0);
}