int print_int(t_tag *tag, intmax_t nbr) { char *prefix; unsigned int nbr_strlen; unsigned int nbr_len; int cut; prefix = NULL; cut = 0; nbr_len = nbr_length(nbr, "0123456789"); nbr_strlen = nbr_strlength(tag, nbr, "0123456789"); if ((nbr < 0 || tag->flag_plus || tag->flag_space) && (cut += 1)) nbr_strlen = handle_prefix(nbr, prefix, tag); else if (tag->has_width && !tag->flag_minus && !tag->flag_zero) print_width_pad(nbr_strlen, tag->width, ' '); nbr = (nbr < 0 ? -nbr : nbr); if (tag->has_width && tag->flag_zero) print_width_pad(nbr_strlen - cut, tag->width, '0'); else if (tag->has_precision) print_width_pad(ft_getsize(nbr), tag->precision, '0'); ft_putnbr(nbr); if (tag->has_width && tag->flag_minus) print_width_pad(nbr_strlen - cut, tag->width, ' '); if (tag->has_width) return (ft_max(tag->width + cut, nbr_strlen)); return (nbr_strlen); }
void ft_parser(char *file, t_env *e) { int fd; if ((fd = open(file, O_RDONLY)) == -1) exit(ft_perror("Le fichier est introuvable.")); ft_getsize(e, fd); ft_getmap(e, fd); close(fd); }
static int ft_getsize(intmax_t nbr) { if (nbr < 10 && nbr > -10) { if (nbr < 10 && nbr >= 0) return (1); return (2); } return (ft_getsize(nbr / 10) + 1); }
int ft_handlewidth_digit(t_elem list, long long numb, char *finder) { int i; long long size; size = ft_getsize(finder, numb); i = 0; i = ft_handlezero_int(list, finder, numb, i); if (list.plus > 0 && list.zero == 0 && list.point != 0 && !list.minus && (int)numb >= 0) i += ft_putchar('+'); if (list.width && list.size == 1 && list.point && !list.minus && finder[-1] != 'z') i += ft_putchar('-'); if (list.zero > 0 && list.point == 0 && list.width > size && list.plus == 0 && !list.minus && !list.whitespace && !numb) i += ft_putchar('0'); if (list.point && list.point > size && !list.minus) i += ft_putnchar('0', list.point - size); return (i); }
int ft_handlespace_int(t_elem list, char *finder, long long numb, int i) { long long size; size = ft_getsize(finder, numb); if ((list.width && list.width > list.point && list.width >= size && list.point) || (list.width && list.width > list.point && list.width > size && list.minus && ((list.pointzero) || (list.zero)))) { if (list.point < size && !numb) i = ft_putnchar(' ', list.width - list.minus - list.plus); else if (list.point < size) i = ft_putnchar(' ', list.width - size - list.whitespace - list.size - ((list.plus && (((int)numb >= 0) || (finder[-1] == 'z'))) ? list.plus : 0)); else if ((i = ft_put_spaces(list, finder, numb, i))) return (i); } return (i); }
char *ft_itoa(int n) { char *result; long nbr; size_t i; size_t sign; nbr = (long)n; sign = (n < 0) ? 1 : 0; nbr = (sign == 1) ? -1 * nbr : nbr; i = ft_getsize(nbr, sign); if ((result = malloc(i + 1)) == NULL) return (NULL); result[i] = '\0'; while (i-- != sign) { result[i] = nbr % 10 + '0'; nbr = nbr / 10; } result[0] = (sign == 1) ? '-' : result[0]; return (result); }
char *ft_anytoa(uint64_t n, int pre, int flag) { char *result; size_t i; size_t j; i = ft_getsize(n); if (flag) i += ((i - 1) / 3); i = ((int)i < pre) ? pre : i; if ((result = malloc(i + 1)) == NULL) return (NULL); result[i] = '\0'; j = 0; while (i--) { result[i] = n % 10 + '0'; if ((++j % 3) == 0 && flag && (n / 10)) result[--i] = *localeconv()->thousands_sep; n /= 10; } return (result); }