functions under 25 lines
This commit is contained in:
parent
c54a9928f4
commit
02b96bca41
6 changed files with 61 additions and 73 deletions
6
ls/.tags
6
ls/.tags
|
|
@ -6,11 +6,14 @@ ft_ent_print src/lib_dirents.c /^void ft_ent_print(t_list *ent, char *opts, t_ls
|
||||||
ft_ent_sort src/lib_dirents.c /^void ft_ent_sort(t_list **ent, char *opts)$/
|
ft_ent_sort src/lib_dirents.c /^void ft_ent_sort(t_list **ent, char *opts)$/
|
||||||
ft_error_dir src/lib_error.c /^void ft_error_dir(char *s)$/
|
ft_error_dir src/lib_error.c /^void ft_error_dir(char *s)$/
|
||||||
ft_error_option src/lib_error.c /^void ft_error_option(char c)$/
|
ft_error_option src/lib_error.c /^void ft_error_option(char c)$/
|
||||||
|
ft_ls_dirs src/ft_ls.c /^void ft_ls_dirs(t_list *dir, char *opts)$/
|
||||||
|
ft_ls_files src/ft_ls.c /^void ft_ls_files(t_list *ent, t_list *dir, char *o/
|
||||||
ft_ls_long src/ft_ls_long.c /^int ft_ls_long(t_list *ent, t_lsdata *topdir)$/
|
ft_ls_long src/ft_ls_long.c /^int ft_ls_long(t_list *ent, t_lsdata *topdir)$/
|
||||||
ft_ls_long_date src/lib_ls_long.c /^void ft_ls_long_date(struct stat *stat)$/
|
ft_ls_long_date src/lib_ls_long.c /^void ft_ls_long_date(struct stat *stat)$/
|
||||||
ft_ls_long_lnk src/lib_ls_long2.c /^int ft_ls_long_lnk(t_lsdata *data)$/
|
ft_ls_long_lnk src/lib_ls_long2.c /^int ft_ls_long_lnk(t_lsdata *data)$/
|
||||||
ft_ls_long_middle src/lib_ls_long.c /^int ft_ls_long_middle(struct stat *stat, t_pads */
|
ft_ls_long_middle src/lib_ls_long.c /^int ft_ls_long_middle(struct stat *stat, t_pads */
|
||||||
ft_ls_long_pads src/lib_ls_long2.c /^int ft_ls_long_pads(t_list *ent, t_pads *pads)$/
|
ft_ls_long_pads src/lib_ls_long2.c /^int ft_ls_long_pads(t_list *ent, t_pads *pads)$/
|
||||||
|
ft_ls_long_print src/ft_ls_long.c /^int ft_ls_long_print(t_list *ent, t_pads pads)$/
|
||||||
ft_ls_long_rights src/lib_ls_long2.c /^void ft_ls_long_rights(int st_mode)$/
|
ft_ls_long_rights src/lib_ls_long2.c /^void ft_ls_long_rights(int st_mode)$/
|
||||||
ft_ls_long_total src/lib_ls_long2.c /^void ft_ls_long_total(t_list *ent)$/
|
ft_ls_long_total src/lib_ls_long2.c /^void ft_ls_long_total(t_list *ent)$/
|
||||||
ft_ls_long_type src/lib_ls_long.c /^void ft_ls_long_type(mode_t m)$/
|
ft_ls_long_type src/lib_ls_long.c /^void ft_ls_long_type(mode_t m)$/
|
||||||
|
|
@ -20,5 +23,6 @@ ft_lsdata_cmp0 src/lib_lsdata.c /^int ft_lsdata_cmp0(t_lsdata *dat, char *datar
|
||||||
ft_lsdata_cmp_name src/lib_lsdata.c /^int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata */
|
ft_lsdata_cmp_name src/lib_lsdata.c /^int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata */
|
||||||
ft_lsdata_cmp_time src/lib_lsdata.c /^int ft_lsdata_cmp_time(t_lsdata *dat1, t_lsdata */
|
ft_lsdata_cmp_time src/lib_lsdata.c /^int ft_lsdata_cmp_time(t_lsdata *dat1, t_lsdata */
|
||||||
ft_lsdata_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data)$/
|
ft_lsdata_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data)$/
|
||||||
ft_parse_ls src/lib_parse.c /^void ft_parse_ls(int ac, char **av, t_list **dir, /
|
ft_parse_ls src/lib_parse.c /^char *ft_parse_ls(int ac, char **av, t_list **dir,/
|
||||||
|
ft_parse_ls_files src/lib_parse.c /^void ft_parse_ls_files(int ac, char **av, t_list */
|
||||||
ft_parse_ls_options src/lib_parse.c /^int ft_parse_ls_options(int ac, char **av, char */
|
ft_parse_ls_options src/lib_parse.c /^int ft_parse_ls_options(int ac, char **av, char */
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,12 @@ typedef struct s_pads
|
||||||
int size;
|
int size;
|
||||||
} t_pads;
|
} t_pads;
|
||||||
|
|
||||||
void ft_parse_ls(int ac, char **av, t_list **dir, t_list **ent, char *opts);
|
void ft_ls_dirs(t_list *dir, char *opts);
|
||||||
|
void ft_ls_files(t_list *ent, t_list *dir, char *opts);
|
||||||
|
|
||||||
|
char *ft_parse_ls(int ac, char **av, t_list **dir, t_list **ent);
|
||||||
int ft_parse_ls_options(int ac, char **av, char *opts);
|
int ft_parse_ls_options(int ac, char **av, char *opts);
|
||||||
|
void ft_parse_ls_files(int ac, char **av, t_list **dir, t_list **ent);
|
||||||
|
|
||||||
void ft_lsdata_filename(t_lsdata *data);
|
void ft_lsdata_filename(t_lsdata *data);
|
||||||
int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2);
|
int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2);
|
||||||
|
|
@ -43,7 +47,9 @@ t_list *ft_ent_get_dirs(t_list *ent);
|
||||||
t_list *ft_dir_get_ents(t_lsdata *dir);
|
t_list *ft_dir_get_ents(t_lsdata *dir);
|
||||||
|
|
||||||
void ft_ls_short(t_list *ent);
|
void ft_ls_short(t_list *ent);
|
||||||
|
|
||||||
int ft_ls_long(t_list *ent, t_lsdata *topdir);
|
int ft_ls_long(t_list *ent, t_lsdata *topdir);
|
||||||
|
int ft_ls_long_print(t_list *ent, t_pads pads);
|
||||||
|
|
||||||
void ft_ls_long_total(t_list *ent);
|
void ft_ls_long_total(t_list *ent);
|
||||||
int ft_ls_long_pads(t_list *ent, t_pads *pads);
|
int ft_ls_long_pads(t_list *ent, t_pads *pads);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
int ft_ls_long(t_list *ent, t_lsdata *topdir)
|
int ft_ls_long(t_list *ent, t_lsdata *topdir)
|
||||||
{
|
{
|
||||||
t_lsdata *data;
|
|
||||||
struct stat stat;
|
|
||||||
struct dirent *dirent;
|
|
||||||
t_pads pads = {0, 0, 0, 0};
|
t_pads pads = {0, 0, 0, 0};
|
||||||
|
|
||||||
if (topdir)
|
if (topdir)
|
||||||
|
|
@ -13,22 +10,33 @@ int ft_ls_long(t_list *ent, t_lsdata *topdir)
|
||||||
return (1);
|
return (1);
|
||||||
while (ent)
|
while (ent)
|
||||||
{
|
{
|
||||||
data = ent->content;
|
if (ft_ls_long_print(ent, pads))
|
||||||
stat = data->stat;
|
return (1);
|
||||||
dirent = data->dirent;
|
|
||||||
ent = ent->next;
|
ent = ent->next;
|
||||||
|
|
||||||
ft_ls_long_type(stat.st_mode);
|
|
||||||
ft_ls_long_rights(stat.st_mode);
|
|
||||||
if (ft_ls_long_xattr(data->path))
|
|
||||||
return (1);
|
|
||||||
if (ft_ls_long_middle(&stat, &pads))
|
|
||||||
return (1);
|
|
||||||
ft_ls_long_date(&stat);
|
|
||||||
ft_printf(" ");
|
|
||||||
ft_lsdata_filename(data);
|
|
||||||
if (ft_ls_long_lnk(data))
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_ls_long_print(t_list *ent, t_pads pads)
|
||||||
|
{
|
||||||
|
t_lsdata *data;
|
||||||
|
struct stat stat;
|
||||||
|
struct dirent *dirent;
|
||||||
|
|
||||||
|
data = ent->content;
|
||||||
|
stat = data->stat;
|
||||||
|
dirent = data->dirent;
|
||||||
|
ent = ent->next;
|
||||||
|
ft_ls_long_type(stat.st_mode);
|
||||||
|
ft_ls_long_rights(stat.st_mode);
|
||||||
|
if (ft_ls_long_xattr(data->path))
|
||||||
|
return (1);
|
||||||
|
if (ft_ls_long_middle(&stat, &pads))
|
||||||
|
return (1);
|
||||||
|
ft_ls_long_date(&stat);
|
||||||
|
ft_printf(" ");
|
||||||
|
ft_lsdata_filename(data);
|
||||||
|
if (ft_ls_long_lnk(data))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ t_list *ft_ent_get_dirs(t_list *ent)
|
||||||
t_list *dir;
|
t_list *dir;
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
|
|
||||||
/* ft_printf("checking dir: %s\n", topdir->path); */
|
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
while (ent)
|
while (ent)
|
||||||
{
|
{
|
||||||
|
|
@ -56,19 +55,12 @@ t_list *ft_ent_get_dirs(t_list *ent)
|
||||||
dirent = data->dirent;
|
dirent = data->dirent;
|
||||||
tmp = ent;
|
tmp = ent;
|
||||||
ent = ent->next;
|
ent = ent->next;
|
||||||
/* ft_printf("checking: %s\n", data->path); */
|
|
||||||
if (dirent->d_type == DT_DIR
|
if (dirent->d_type == DT_DIR
|
||||||
&& ft_strcmp(dirent->d_name, ".")
|
&& ft_strcmp(dirent->d_name, ".")
|
||||||
&& ft_strcmp(dirent->d_name, ".."))
|
&& ft_strcmp(dirent->d_name, ".."))
|
||||||
{
|
{
|
||||||
/* data->path = ft_strjoin(topdir->path, "/"); */
|
|
||||||
/* data->path = ft_strjoin(data->path, dirent->d_name); */
|
|
||||||
/* stat(data->path, &data->stat); */
|
|
||||||
/* ft_printf("found dir: %s\n", data->path); */
|
|
||||||
ft_lsteadd(&dir, tmp);
|
ft_lsteadd(&dir, tmp);
|
||||||
}
|
}
|
||||||
/* else */
|
|
||||||
/* ft_printf("%s is not a dir\n", data->path); */
|
|
||||||
}
|
}
|
||||||
return (dir);
|
return (dir);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,42 @@
|
||||||
#include "ftls.h"
|
#include "ftls.h"
|
||||||
|
|
||||||
void ft_parse_ls(int ac, char **av, t_list **dir, t_list **ent, char *opts)
|
char *ft_parse_ls(int ac, char **av, t_list **dir, t_list **ent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *opts;
|
||||||
t_lsdata data;
|
t_lsdata data;
|
||||||
DIR *stream;
|
|
||||||
|
|
||||||
ft_bzero(opts, 7);
|
if (!(opts = (char *)ft_strnew(sizeof(char) * 7)))
|
||||||
data.dirent = NULL;
|
return (NULL);
|
||||||
i = ft_parse_ls_options(ac, av, opts);
|
i = ft_parse_ls_options(ac, av, opts);
|
||||||
/* ft_strlsort(av + i, ac - i, &ft_strcmp); */
|
ft_strcat(opts, (ac - i <= 1) ? "0" : "");
|
||||||
if (ac - i <= 1)
|
|
||||||
ft_strcat(opts, "0");
|
|
||||||
/* ft_printf("options: %s\n", opts); */
|
|
||||||
/* ft_printf("%i, %i\n", i, ac); */
|
|
||||||
if (i == ac)
|
if (i == ac)
|
||||||
{
|
{
|
||||||
data.path = ft_strdup(".");
|
data.path = ft_strdup(".");
|
||||||
/* ft_printf("stat ret: %i\n", stat(data.path, &data.stat)); */
|
data.dirent = NULL;
|
||||||
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
||||||
}
|
}
|
||||||
|
ft_parse_ls_files(ac - i, av + i, dir, ent);
|
||||||
|
return (opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_parse_ls_files(int ac, char **av, t_list **dir, t_list **ent)
|
||||||
|
{
|
||||||
|
DIR *stream;
|
||||||
|
t_lsdata data;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data.dirent = NULL;
|
||||||
|
i = 0;
|
||||||
while (i < ac)
|
while (i < ac)
|
||||||
{
|
{
|
||||||
data.path = ft_strdup(av[i]);
|
data.path = ft_strdup(av[i]);
|
||||||
if (lstat(data.path, &data.stat) < 0)
|
if (lstat(data.path, &data.stat) < 0)
|
||||||
ft_error_dir(data.path);
|
ft_error_dir(data.path);
|
||||||
else if (!(stream = opendir(data.path)))
|
else if (!(stream = opendir(data.path)))
|
||||||
{
|
|
||||||
/* ft_printf("found file: %s\n", data.path); */
|
|
||||||
ft_lstadd(ent, ft_lstnew(&data, sizeof(data)));
|
ft_lstadd(ent, ft_lstnew(&data, sizeof(data)));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* ft_printf("found dir: %s\n", data.path); */
|
|
||||||
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
||||||
closedir(stream);
|
closedir(stream);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,16 @@
|
||||||
#include "ftls.h"
|
#include "ftls.h"
|
||||||
|
#include "ftls.h"
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_list *dir;
|
t_list *dir;
|
||||||
t_list *dir_r;
|
|
||||||
t_list *ent;
|
t_list *ent;
|
||||||
t_lsdata *dirdata;
|
|
||||||
|
|
||||||
char *opts;
|
char *opts;
|
||||||
|
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
ent = NULL;
|
ent = NULL;
|
||||||
opts = (char *)malloc(sizeof(char) * 7);
|
opts = ft_parse_ls(ac, av, &dir, &ent);
|
||||||
ft_parse_ls(ac, av, &dir, &ent, opts);
|
ft_ls_files(ent, dir, opts);
|
||||||
if (ent)
|
ft_ls_dirs(dir, opts);
|
||||||
{
|
|
||||||
ft_ent_filter(&ent, opts);
|
|
||||||
ft_ent_sort(&ent, opts);
|
|
||||||
ft_ent_print(ent, opts, NULL, dir);
|
|
||||||
}
|
|
||||||
ft_ent_sort(&dir, opts);
|
|
||||||
while (dir)
|
|
||||||
{
|
|
||||||
dirdata = dir->content;
|
|
||||||
dir = dir->next;
|
|
||||||
/* ft_lstfree(ent); */
|
|
||||||
ent = ft_dir_get_ents(dirdata);
|
|
||||||
ft_ent_filter(&ent, opts);
|
|
||||||
ft_ent_sort(&ent, opts);
|
|
||||||
ft_ent_print(ent, opts, dirdata, dir);
|
|
||||||
if (ft_strchr(opts, 'R'))
|
|
||||||
{
|
|
||||||
dir_r = ft_ent_get_dirs(ent);
|
|
||||||
ft_lst_merge(&dir_r, dir);
|
|
||||||
dir = dir_r;
|
|
||||||
}
|
|
||||||
/* if (dir) */
|
|
||||||
/* ft_printf("\n"); */
|
|
||||||
/* ft_lsdata_print(dir); */
|
|
||||||
}
|
|
||||||
return (errno);
|
return (errno);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue