int my_ls(char *path, int *apply) { t_file *file; DIR *dir_p; t_dirent *entry; if (init_t(&file, dir_p) == -1) return (-1); if ((dir_p = opendir(path)) == NULL) { if (check_if_file(path, apply) == 1) return (0); my_printf("ERROR: opendir: "); my_printf("%s\n", strerror(errno)); return (-1); } while (entry = readdir(dir_p)) { if (entry->d_name[0] != '.' && apply[3] != 1) stack_sort_list(&file, entry, path, apply); else if (apply[3] == 1) stack_sort_list(&file, entry, path, apply); } apply_flags(file, apply, path); closedir(dir_p); }
int basic_u_conv(va_list *ap, t_format *format) { unsigned int conv; char *s; size_t len; conv = va_arg(*ap, unsigned int); s = ft_utoa(conv, 10); apply_flags(&s, format); len = ft_strlen(s); write(FD_OUT, s, len); return (len); }
int basic_d_conv(va_list *ap, t_format *format) { int conv; char *s; size_t len; if (format->has_star) format->m_width = va_arg(*ap, int); conv = va_arg(*ap, int); s = ft_stoa(conv); apply_flags(&s, format); len = ft_strlen(s); write(FD_OUT, s, len); free(s); return (len); }
void apply_flags_s(t_arg *l, char *arg) { if (ft_strchr(l->flags, '+') && l->neg == 0 && l->conv[0] != 'u' && l->conv[0] != 'U' && l->conv[0] != 'c' && l->conv[0] != 'C' && l->conv[0] != 'o' && l->conv[0] != 'O' && l->conv[0] != 's' && l->conv[0] != 'S' && l->conv[0] != 'p' && l->conv[0] != 'x' && l->conv[0] != 'X') { l->str_len++; write(1, "+", 1); } if (ft_strchr(l->flags, ' ') && l->neg == 0 && l->conv[0] != '%' && l->conv[0] != 'u' && l->conv[0] != 'U' && l->conv[0] != 'c' && l->conv[0] != 'C' && l->conv[0] != 'o' && l->conv[0] != 'O' && !ft_strchr(l->flags, '+') && l->conv[0] != 'p' && l->conv[0] != 's' && l->conv[0] != 'S' && l->conv[0] != 'x' && l->conv[0] != 'X') { l->str_len++; write(1, " ", 1); } apply_flags(l, arg); }
str = NULL; if (f.modifier == 0 && f.conversion != 'O' && f.conversion != 'U') { m.ui = va_arg(args, unsigned int); if (f.conversion == 'o') str = ft_itoa_base_ulli((unsigned long long int)m.ui, 8, 'o'); else if (f.conversion == 'x') str = ft_itoa_base_ulli((unsigned long long int)m.ui, 16, 'x'); else if (f.conversion == 'X') str = ft_itoa_base_ulli((unsigned long long int)m.ui, 16, 'X'); else if (f.conversion == 'u') str = ft_itoa_ulli((unsigned long long int)m.ui); } str = unsigned_conv2(str, args, f, m); str = apply_flags(str, f); len = ft_strlen(str); free(str); free(f.param); return (len); } char *unsigned_conv2(char *str, va_list args, t_flags f, t_modifier m) { if (f.modifier == 1 && f.conversion != 'O' && f.conversion != 'U') { m.uc = va_arg(args, unsigned int); if (f.conversion == 'o') return (ft_itoa_base_ulli((unsigned long long int)m.uc, 8, 'o')); else if (f.conversion == 'x') return (ft_itoa_base_ulli((unsigned long long int)m.uc, 16, 'x'));