pf_s_up.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* pf_s_up.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/02/27 01:50:12 by bchanot #+# #+# */
  9. /* Updated: 2016/08/11 21:26:03 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libftprintf.h"
  13. #include <wchar.h>
  14. int pf_s_up(va_list ap, t_inf inf)
  15. {
  16. wchar_t *s;
  17. char *str;
  18. int len;
  19. len = inf.prec == -1 ? 1 : 0;
  20. if ((s = va_arg(ap, wchar_t *)) == NULL)
  21. str = ft_strdup("(null)");
  22. else
  23. str = ft_widestr(s);
  24. if (inf.width > 0 && inf.min == 0)
  25. while (pf_width_s(str, inf, len) && len++ >= 0)
  26. ft_putchar_fd((inf.zero ? '0' : ' '), inf.fd);
  27. if (inf.prec > 0 && inf.prec < (int)ft_strlen(str))
  28. len += pf_putnstr(str, inf.prec, inf.fd);
  29. else
  30. len += pf_putstr(str, inf.fd);
  31. if (inf.width > 0 && inf.min == 1)
  32. while (len < inf.width && len++ >= 0)
  33. ft_putchar_fd(' ', inf.fd);
  34. if (s == NULL)
  35. ft_memdel((void **)&str);
  36. return (len);
  37. }