diff --git a/ls/.tags b/ls/.tags index 36804642..c248b634 100644 --- a/ls/.tags +++ b/ls/.tags @@ -1,6 +1,10 @@ FT_MAX_WR src/lib_ls_long2.c /^#define FT_MAX_WR(a,b) a = FT_MAX(a,b)$/ Mmain src/main.c /^int main(int ac, char **av)$/ -ft_dir_get_ents src/ft_dir_get_ents.c /^t_list *ft_dir_get_ents(t_lsdata *topdir)$/ +ft_cmp_atime src/lib_time.c /^int ft_cmp_atime(t_lsdata *dat1, t_lsdata *dat2)$/ +ft_cmp_btime src/lib_time.c /^int ft_cmp_btime(t_lsdata *dat1, t_lsdata *dat2)$/ +ft_cmp_ctime src/lib_time.c /^int ft_cmp_ctime(t_lsdata *dat1, t_lsdata *dat2)$/ +ft_cmp_mtime src/lib_time.c /^int ft_cmp_mtime(t_lsdata *dat1, t_lsdata *dat2)$/ +ft_dir_get_ents src/ft_dir_get_ents.c /^t_list *ft_dir_get_ents(t_lsdata *topdir, int *opt/ ft_ent_filter src/lib_ent.c /^void ft_ent_filter(t_list **ent, int opts)$/ ft_ent_free src/ft_ent_free.c /^void ft_ent_free(void *ptr, size_t size)$/ ft_ent_get_dirs src/ft_ent_get_dirs.c /^t_list *ft_ent_get_dirs(t_list **ent)$/ @@ -13,21 +17,22 @@ ft_error_option src/lib_error.c /^void ft_error_option(char c)$/ ft_getopts src/lib_parse.c /^static int ft_getopts(char *str)$/ ft_ls_dirs src/ft_ls.c /^void ft_ls_dirs(t_list *dir, int opts)$/ ft_ls_files src/ft_ls.c /^void ft_ls_files(t_list **ent, t_list **dir, t_lsd/ -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 src/ft_ls_long.c /^int ft_ls_long(t_list *ent, t_lsdata *topdir, int/ +ft_ls_long_date src/lib_ls_long.c /^void ft_ls_long_date(struct stat *stat, int opts)$/ 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_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_print src/ft_ls_long.c /^int ft_ls_long_print(t_list *ent, t_lsdata *topdi/ ft_ls_long_rights src/lib_ls_long2.c /^void ft_ls_long_rights(mode_t m)$/ 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_xattr src/lib_ls_long2.c /^int ft_ls_long_xattr(mode_t m, char *path)$/ ft_ls_parse src/lib_parse.c /^int ft_ls_parse(int ac, char **av, t_list **dir,/ -ft_ls_parse_files src/lib_parse.c /^static void ft_ls_parse_files(int ac, char **av, t/ +ft_ls_parse_files src/lib_parse.c /^static void ft_ls_parse_files(int ac, char **av, i/ ft_ls_parse_options src/lib_parse.c /^static int ft_ls_parse_options(int ac, char **av, / -ft_ls_short src/ft_ls_short.c /^void ft_ls_short(t_list *ent)$/ +ft_ls_short src/ft_ls_short.c /^void ft_ls_short(t_list *ent, t_lsdata *topdir, in/ ft_lsdata_cmp0 src/lib_lsdata.c /^int ft_lsdata_cmp0(t_lsdata *data, char *dataref)/ +ft_lsdata_cmpA src/lib_lsdata.c /^int ft_lsdata_cmpA(t_lsdata *data, char *dataref)/ 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_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data)$/ +ft_lsdata_cmp_size src/lib_lsdata.c /^int ft_lsdata_cmp_size(t_lsdata *dat1, t_lsdata */ +ft_lsdata_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data, t_lsdata */ diff --git a/ls/Session.vim b/ls/Session.vim index 9f7cba2f..7e512cca 100644 --- a/ls/Session.vim +++ b/ls/Session.vim @@ -8,28 +8,28 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' let s:wipebuf = bufnr('%') endif set shortmess=aoO -badd +116 src/lib_ls_long2.c -badd +26 src/ft_ls_long.c -badd +1 includes/ft_ls.h +badd +62 src/lib_ls_long2.c +badd +37 src/ft_ls_long.c +badd +82 includes/ft_ls.h badd +60 ~/.tmux.conf -badd +29 src/lib_ls_long.c -badd +35 src/lib_lsdata.c -badd +34 src/lib_parse.c +badd +35 src/lib_ls_long.c +badd +29 src/lib_lsdata.c +badd +39 src/lib_parse.c badd +22 libft/src/ft_printf/lib_pad.c badd +19 libft/src/ft_printf/lib_pad_sharp.c badd +14 libft/src/lst/ft_lst_filter.c badd +14 src/lib_dirents.c badd +21 src/main.c -badd +30 src/ft_ls.c +badd +42 src/ft_ls.c badd +23 src/ft_ent_free.c -badd +1 Makefile -badd +21 src/lib_error.c +badd +17 Makefile +badd +38 src/lib_error.c badd +32 src/lib_dirs.c -badd +25 src/ft_dir_get_ents.c +badd +36 src/ft_dir_get_ents.c badd +69 libft/src/ft_printf/ft_printf.c badd +46 libft/includes/ft_printf.h badd +2 libft/src/printing/ft_putstr_fd.c -badd +11 libft/includes/libft.h +badd +112 libft/includes/libft.h badd +2 libft/src/ft_printf/lib_fmt.c badd +1 src/.lib_dirents.c.swo badd +1 ft_ls @@ -41,12 +41,12 @@ badd +19 libft/src/mem/ft_memdel.c badd +32 libft/src/lst/ft_lst_delif.c badd +22 libft/src/lst/ft_lstdelone.c badd +25 libft/src/lst/ft_lst_removeif.c -badd +42 ~/.vimrc -badd +12 src/ft_ent_has_dir.c +badd +1 ~/.vimrc +badd +24 src/ft_ent_has_dir.c badd +35 src/ft_ent_get_dirs.c -badd +50 src/lib_ent.c +badd +36 src/lib_ent.c badd +11 .Makefile.swp -badd +18 ~/dotfiles/vim.symlink/plugins.vim +badd +29 ~/dotfiles/vim.symlink/plugins.vim badd +22 libft/src/str/ft_strsub.c badd +1 libft/Makefile badd +14 libft/src/btree/btree_print.c @@ -54,6 +54,15 @@ badd +14 libft/src/printing/ft_putaddr.c badd +13 libft/src/str/ft_strinsert.c badd +20 libft/src/str/ft_strdel.c badd +22 libft/src/str/ft_strjoin.c +badd +0 libft/src/mem/ft_memset.c +badd +35 libft/includes/lst.h +badd +15 libft/src/sstr/ft_sstrsort.c +badd +25 libft/src/lst/ft_lstsort.c +badd +20 libft/src/lst/ft_lst_sort.c +badd +5 ~/dotfiles/vim.symlink/aliases.vim +badd +0 lol +badd +18 src/ft_ls_short.c +badd +30 src/lib_time.c args src/lib_ls_long2.c edit includes/ft_ls.h set splitbelow splitright @@ -65,8 +74,8 @@ set nosplitbelow set nosplitright wincmd t set winheight=1 winwidth=1 -exe 'vert 1resize ' . ((&columns * 98 + 98) / 196) -exe 'vert 2resize ' . ((&columns * 97 + 98) / 196) +exe 'vert 1resize ' . ((&columns * 90 + 102) / 204) +exe 'vert 2resize ' . ((&columns * 113 + 102) / 204) argglobal setlocal fdm=manual setlocal fde=0 @@ -77,15 +86,15 @@ setlocal fml=1 setlocal fdn=20 setlocal fen silent! normal! zE -let s:l = 96 - ((77 * winheight(0) + 40) / 80) +let s:l = 28 - ((27 * winheight(0) + 40) / 80) if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt -96 -normal! 029l +28 +normal! 025l wincmd w argglobal -edit Makefile +edit src/main.c setlocal fdm=manual setlocal fde=0 setlocal fmr={{{,}}} @@ -95,16 +104,60 @@ setlocal fml=1 setlocal fdn=20 setlocal fen silent! normal! zE -let s:l = 17 - ((0 * winheight(0) + 40) / 80) +let s:l = 25 - ((24 * winheight(0) + 40) / 80) if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt -17 -normal! 011l +25 +normal! 01l wincmd w -exe 'vert 1resize ' . ((&columns * 98 + 98) / 196) -exe 'vert 2resize ' . ((&columns * 97 + 98) / 196) -tabedit src/main.c +exe 'vert 1resize ' . ((&columns * 90 + 102) / 204) +exe 'vert 2resize ' . ((&columns * 113 + 102) / 204) +tabedit src/lib_parse.c +set splitbelow splitright +set nosplitbelow +set nosplitright +wincmd t +set winheight=1 winwidth=1 +argglobal +setlocal fdm=manual +setlocal fde=0 +setlocal fmr={{{,}}} +setlocal fdi=# +setlocal fdl=0 +setlocal fml=1 +setlocal fdn=20 +setlocal fen +silent! normal! zE +let s:l = 80 - ((55 * winheight(0) + 40) / 80) +if s:l < 1 | let s:l = 1 | endif +exe s:l +normal! zt +80 +normal! 02l +tabedit src/lib_time.c +set splitbelow splitright +set nosplitbelow +set nosplitright +wincmd t +set winheight=1 winwidth=1 +argglobal +setlocal fdm=manual +setlocal fde=0 +setlocal fmr={{{,}}} +setlocal fdi=# +setlocal fdl=0 +setlocal fml=1 +setlocal fdn=20 +setlocal fen +silent! normal! zE +let s:l = 29 - ((28 * winheight(0) + 40) / 80) +if s:l < 1 | let s:l = 1 | endif +exe s:l +normal! zt +29 +normal! 0 +tabedit src/ft_ls.c set splitbelow splitright wincmd _ | wincmd | vsplit @@ -114,51 +167,8 @@ set nosplitbelow set nosplitright wincmd t set winheight=1 winwidth=1 -exe 'vert 1resize ' . ((&columns * 98 + 98) / 196) -exe 'vert 2resize ' . ((&columns * 97 + 98) / 196) -argglobal -setlocal fdm=manual -setlocal fde=0 -setlocal fmr={{{,}}} -setlocal fdi=# -setlocal fdl=0 -setlocal fml=1 -setlocal fdn=20 -setlocal fen -silent! normal! zE -let s:l = 21 - ((20 * winheight(0) + 40) / 80) -if s:l < 1 | let s:l = 1 | endif -exe s:l -normal! zt -21 -normal! 01l -wincmd w -argglobal -edit src/ft_ls.c -setlocal fdm=manual -setlocal fde=0 -setlocal fmr={{{,}}} -setlocal fdi=# -setlocal fdl=0 -setlocal fml=1 -setlocal fdn=20 -setlocal fen -silent! normal! zE -let s:l = 31 - ((30 * winheight(0) + 40) / 80) -if s:l < 1 | let s:l = 1 | endif -exe s:l -normal! zt -31 -normal! 03l -wincmd w -exe 'vert 1resize ' . ((&columns * 98 + 98) / 196) -exe 'vert 2resize ' . ((&columns * 97 + 98) / 196) -tabedit src/ft_dir_get_ents.c -set splitbelow splitright -set nosplitbelow -set nosplitright -wincmd t -set winheight=1 winwidth=1 +exe 'vert 1resize ' . ((&columns * 102 + 102) / 204) +exe 'vert 2resize ' . ((&columns * 101 + 102) / 204) argglobal setlocal fdm=manual setlocal fde=0 @@ -174,7 +184,28 @@ if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt 24 -normal! 0 +normal! 08l +wincmd w +argglobal +edit src/lib_ls_long.c +setlocal fdm=manual +setlocal fde=0 +setlocal fmr={{{,}}} +setlocal fdi=# +setlocal fdl=0 +setlocal fml=1 +setlocal fdn=20 +setlocal fen +silent! normal! zE +let s:l = 38 - ((36 * winheight(0) + 40) / 80) +if s:l < 1 | let s:l = 1 | endif +exe s:l +normal! zt +38 +normal! 03l +wincmd w +exe 'vert 1resize ' . ((&columns * 102 + 102) / 204) +exe 'vert 2resize ' . ((&columns * 101 + 102) / 204) tabedit src/lib_ent.c set splitbelow splitright set nosplitbelow @@ -191,13 +222,13 @@ setlocal fml=1 setlocal fdn=20 setlocal fen silent! normal! zE -let s:l = 49 - ((48 * winheight(0) + 40) / 80) +let s:l = 32 - ((31 * winheight(0) + 40) / 80) if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt -49 -normal! 01l -tabnext 4 +32 +normal! 019l +tabnext 5 if exists('s:wipebuf') silent exe 'bwipe ' . s:wipebuf endif diff --git a/ls/includes/ft_ls.h b/ls/includes/ft_ls.h index 5dc851af..d811c456 100644 --- a/ls/includes/ft_ls.h +++ b/ls/includes/ft_ls.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:10:03 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:55:20 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:40:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,19 +15,31 @@ # define LS_LEGAL_OPTS "larRt" # define LS_MSG_ILLEGAL_OPT "ft_ls: illegal option -- %c\n" # define LS_MSG_USAGE "usage: ls [-%s] [file ...]\n" -# define LS_MSG_FILE_ERR "ls: %s: no such file or directory\n" -# define LS_MSG_ACC_ERR "ls: %s: Permission Denied\n" +# define LS_MSG_FILE_ERR "ls: %s: No such file or directory\n" +# define LS_MSG_ACC_ERR "ls: %s: Permission denied\n" -# define OPTS_LL 0x0001 -# define OPTS_LA 0x0002 -# define OPTS_LR 0x0004 -# define OPTS_UR 0x0008 -# define OPTS_LT 0x0010 -# define OPTS_ONE 0x0020 -# define OPTS_HEAD 0x1000 +# define OPTS_LA 0x0000001 +# define OPTS_LC 0x0000002 +# define OPTS_LD 0x0000004 +# define OPTS_LF 0x0000008 +# define OPTS_LL 0x0000010 +# define OPTS_LP 0x0000020 +# define OPTS_LR 0x0000040 +# define OPTS_LT 0x0000080 +# define OPTS_LU 0x0000100 +# define OPTS_UA 0x0000200 +# define OPTS_UR 0x0000400 +# define OPTS_UU 0x0000800 +# define OPTS_US 0x0001000 +# define OPTS_ONE 0x0002000 +# define OPTS_ERR_A 0x0010000 +# define OPTS_HEAD 0x0100000 + +# define TIME_MASK OPTS_LC | OPTS_LU | OPTS_UU # include "libft.h" # include +# include # include # include # include @@ -62,10 +74,16 @@ int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent); void ft_ls_dirs(t_list *dir, int opts); void ft_ls_files(t_list **ent, t_list **dir, t_lsdata *topdir, int *opts); -void ft_lsdata_filename(t_lsdata *data); +int ft_cmp_mtime(t_lsdata *dat1, t_lsdata *dat2); +int ft_cmp_atime(t_lsdata *dat1, t_lsdata *dat2); +int ft_cmp_ctime(t_lsdata *dat1, t_lsdata *dat2); +int ft_cmp_btime(t_lsdata *dat1, t_lsdata *dat2); + +void ft_lsdata_filename(t_lsdata *data, t_lsdata *topdir, int opts); int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2); -int ft_lsdata_cmp_time(t_lsdata *dat1, t_lsdata *dat2); +int ft_lsdata_cmp_size(t_lsdata *dat1, t_lsdata *dat2); int ft_lsdata_cmp0(t_lsdata *dat1, char *dataref); +int ft_lsdata_cmpA(t_lsdata *data, char *dataref); void ft_ent_filter(t_list **ent, int opts); void ft_ent_sort(t_list **ent, int opts); @@ -75,12 +93,12 @@ int ft_ent_has_dir(t_list *ent); t_list *ft_ent_get_dirs(t_list **ent); t_list *ft_ent_get_dirs(t_list **ent); -t_list *ft_dir_get_ents(t_lsdata *topdir); +t_list *ft_dir_get_ents(t_lsdata *topdir, int *opts); -void ft_ls_short(t_list *ent); +void ft_ls_short(t_list *ent, t_lsdata *topdir, int opts); -int ft_ls_long(t_list *ent, t_lsdata *topdir); -int ft_ls_long_print(t_list *ent, t_pads pads); +int ft_ls_long(t_list *ent, t_lsdata *topdir, int opts); +int ft_ls_long_print(t_list *ent, t_lsdata *topdir, t_pads pads, int opts); void ft_ls_long_total(t_list *ent); int ft_ls_long_pads(t_list *ent, t_pads *pads); @@ -88,7 +106,7 @@ void ft_ls_long_type(mode_t m); void ft_ls_long_rights(mode_t m); int ft_ls_long_xattr(mode_t m, char *path); int ft_ls_long_middle(struct stat *stat, t_pads *pads); -void ft_ls_long_date(struct stat *stat); +void ft_ls_long_date(struct stat *stat, int opts); int ft_ls_long_lnk(t_lsdata *data); void ft_error_option(char c); diff --git a/ls/libft/includes/libft.h b/ls/libft/includes/libft.h index 3a7b0c6f..216c1b6d 100644 --- a/ls/libft/includes/libft.h +++ b/ls/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/16 10:58:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 13:56:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -119,7 +119,7 @@ size_t ft_lllen_base(long long n, int base); int ft_addrcmp(void *a, void *b); char **ft_sstradd(char **list, char *new); -void ft_sstrsort(char **list, int size, int (*cmp)()); +void ft_sstrsort(char **list, int (*cmp)()); void ft_sstrprint(char **list, char sep); char **ft_sstrdup(char **list); void ft_sstrdel(char **sstr, int index); diff --git a/ls/libft/includes/lst.h b/ls/libft/includes/lst.h index 3b851fff..bff4ef8e 100644 --- a/ls/libft/includes/lst.h +++ b/ls/libft/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2016/11/08 11:25:38 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 14:50:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); t_list *ft_lstnew_range(int a, int b); void ft_lsteadd(t_list **alst, t_list *new); void ft_lstnadd(t_list **alst, t_list *new, int n); -void ft_lst_sort(t_list **begin_list, int (*cmp)()); +void ft_lstsort(t_list **begin_list, int (*cmp)()); void ft_lst_print(t_list *list, void (*printer)()); int ft_lstsize(t_list *lst); t_list *ft_lstlast(t_list *lst); diff --git a/ls/libft/src/lst/ft_lst_sort.c b/ls/libft/src/lst/ft_lst_sort.c deleted file mode 100644 index f7aedb68..00000000 --- a/ls/libft/src/lst/ft_lst_sort.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lst_sort.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/04 11:09:37 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:38 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static void ft_lst_swap(t_list **current) -{ - t_list *tmp; - - tmp = (*current)->next->next; - (*current)->next->next = (*current); - (*current)->next = tmp; -} - -void ft_lst_sort(t_list **begin_list, int (*cmp)()) -{ - t_list *current; - t_list *last; - - current = *begin_list; - if (!*begin_list) - return ; - while (current->next) - { - if ((*cmp)(current->content, current->next->content) > 0) - { - if (current != *begin_list) - last->next = current->next; - else - *begin_list = current->next; - ft_lst_swap(¤t); - current = *begin_list; - } - else - { - last = current; - current = current->next ? current->next : current; - } - } -} diff --git a/ls/libft/src/lst/ft_lstsort.c b/ls/libft/src/lst/ft_lstsort.c index 4f0a8817..725b532f 100644 --- a/ls/libft/src/lst/ft_lstsort.c +++ b/ls/libft/src/lst/ft_lstsort.c @@ -6,44 +6,33 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:58 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 15:43:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static void ft_list_swap(t_list **current) +void ft_lstsort(t_list **begin_list, int (*cmp)()) { + t_list **indirect; t_list *tmp; + t_list *tmp2; - tmp = (*current)->next->next; - (*current)->next->next = (*current); - (*current)->next = tmp; -} - -void ft_list_sort(t_list **begin_list, int (*cmp)()) -{ - t_list *current; - t_list *last; - - current = *begin_list; + indirect = begin_list; if (!*begin_list) return ; - while (current->next) + while (*indirect && (*indirect)->next) { - if ((*cmp)(current->content, current->next->content) > 0) + if ((*cmp)((*indirect)->content, (*indirect)->next->content) > 0) { - if (current != *begin_list) - last->next = current->next; - else - *begin_list = current->next; - ft_list_swap(¤t); - current = *begin_list; + tmp = *indirect; + tmp2 = (*indirect)->next; + (*indirect)->next = (*indirect)->next->next; + *indirect = tmp2; + (*indirect)->next = tmp; + indirect = begin_list; } else - { - last = current; - current = current->next ? current->next : current; - } + indirect = &(*indirect)->next; } } diff --git a/ls/libft/src/path/ft_path_notdir.c b/ls/libft/src/path/ft_path_notdir.c index d85fe56b..b00d21fe 100644 --- a/ls/libft/src/path/ft_path_notdir.c +++ b/ls/libft/src/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/11/16 12:07:21 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 15:46:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ char *ft_path_notdir(char *path) char *ret; ret = path; - if ((slash = ft_strrchr(path, '/'))) + if ((slash = ft_strrchr(path, '/')) && slash != path) ret = slash + 1; return (ret); } diff --git a/ls/libft/src/sstr/ft_sstrsort.c b/ls/libft/src/sstr/ft_sstrsort.c index b2985c70..180d4ea0 100644 --- a/ls/libft/src/sstr/ft_sstrsort.c +++ b/ls/libft/src/sstr/ft_sstrsort.c @@ -6,19 +6,19 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:04:17 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_sstrsort(char **list, int size, int (*cmp)()) +void ft_sstrsort(char **list, int (*cmp)()) { int i; char *tmp; i = 0; - while (i < size - 1) + while (list[i] && list[i + 1]) { if ((*cmp)(list[i], list[i + 1]) > 0) { diff --git a/ls/src/ft_dir_get_ents.c b/ls/src/ft_dir_get_ents.c index 183ff1d4..cee49317 100644 --- a/ls/src/ft_dir_get_ents.c +++ b/ls/src/ft_dir_get_ents.c @@ -6,33 +6,36 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:58:49 by jhalford #+# #+# */ -/* Updated: 2016/11/22 17:11:46 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 16:20:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ls.h" -t_list *ft_dir_get_ents(t_lsdata *topdir) +t_list *ft_dir_get_ents(t_lsdata *topdir, int *opts) { t_list *ent; struct dirent *dirent; t_lsdata data; DIR *stream; + char *prepath; ent = NULL; if (!(stream = opendir(topdir->path))) { - ft_error_access(topdir->path); + *opts |= OPTS_ERR_A; return (NULL); } + prepath = ft_strjoin(topdir->path, "/"); while ((dirent = readdir(stream))) { - data.path = ft_str3join(topdir->path, "/", dirent->d_name); + data.path = ft_strjoin(prepath, dirent->d_name); lstat(data.path, &data.stat); data.dirent = ft_memalloc(sizeof(*dirent) + 1); ft_memcpy(data.dirent, dirent, sizeof(*dirent)); ft_lstadd(&ent, ft_lstnew(&data, sizeof(data))); } + ft_strdel(&prepath); closedir(stream); return (ent); } diff --git a/ls/src/ft_ent_has_dir.c b/ls/src/ft_ent_has_dir.c index 69bc92bd..72e696d5 100644 --- a/ls/src/ft_ent_has_dir.c +++ b/ls/src/ft_ent_has_dir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/16 15:42:54 by jhalford #+# #+# */ -/* Updated: 2016/11/16 15:45:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:24:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/ls/src/ft_ls.c b/ls/src/ft_ls.c index f0b00d6d..7bd93d80 100644 --- a/ls/src/ft_ls.c +++ b/ls/src/ft_ls.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:57:21 by jhalford #+# #+# */ -/* Updated: 2016/11/22 17:11:40 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:53:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ void ft_ls_dirs(t_list *dir, int opts) tmp = dir; dir = dir->next; ft_lstdel(&ent, &ft_ent_free); - ent = ft_dir_get_ents(dirdata); + ent = ft_dir_get_ents(dirdata, &opts); ft_ls_files(&ent, &dir, dirdata, &opts); ft_lstdelone(&tmp, &ft_ent_free); if (opts & OPTS_UR) @@ -44,7 +44,8 @@ void ft_ls_files(t_list **ent, t_list **dir, t_lsdata *topdir, int *opts) { if (ent) { - ft_ent_filter(ent, *opts); + if (topdir) + ft_ent_filter(ent, *opts); ft_ent_sort(ent, *opts); ft_ent_print(*ent, opts, topdir, *dir); } diff --git a/ls/src/ft_ls_long.c b/ls/src/ft_ls_long.c index 77542eff..4cab799a 100644 --- a/ls/src/ft_ls_long.c +++ b/ls/src/ft_ls_long.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:58:05 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:07:01 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 17:39:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ls.h" -int ft_ls_long(t_list *ent, t_lsdata *topdir) +int ft_ls_long(t_list *ent, t_lsdata *topdir, int opts) { t_pads pads; @@ -22,14 +22,14 @@ int ft_ls_long(t_list *ent, t_lsdata *topdir) return (1); while (ent) { - if (ft_ls_long_print(ent, pads)) + if (ft_ls_long_print(ent, topdir, pads, opts)) return (1); ent = ent->next; } return (0); } -int ft_ls_long_print(t_list *ent, t_pads pads) +int ft_ls_long_print(t_list *ent, t_lsdata *topdir, t_pads pads, int opts) { t_lsdata *data; struct stat stat; @@ -45,9 +45,9 @@ int ft_ls_long_print(t_list *ent, t_pads pads) return (1); if (ft_ls_long_middle(&stat, &pads)) return (1); - ft_ls_long_date(&stat); + ft_ls_long_date(&stat, opts); ft_printf(" "); - ft_lsdata_filename(data); + ft_lsdata_filename(data, topdir, opts); if (ft_ls_long_lnk(data)) return (1); return (0); diff --git a/ls/src/ft_ls_short.c b/ls/src/ft_ls_short.c index c409a2eb..d0a4df59 100644 --- a/ls/src/ft_ls_short.c +++ b/ls/src/ft_ls_short.c @@ -6,17 +6,17 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:56:28 by jhalford #+# #+# */ -/* Updated: 2016/11/07 15:29:56 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:50:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ls.h" -void ft_ls_short(t_list *ent) +void ft_ls_short(t_list *ent, t_lsdata *topdir, int opts) { while (ent) { - ft_lsdata_filename(ent->content); + ft_lsdata_filename(ent->content, topdir, opts); ft_printf("\n"); ent = ent->next; } diff --git a/ls/src/lib_ent.c b/ls/src/lib_ent.c index 8cb80412..ebb8fa2c 100644 --- a/ls/src/lib_ent.c +++ b/ls/src/lib_ent.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:00:05 by jhalford #+# #+# */ -/* Updated: 2016/11/22 17:12:03 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:54:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,18 +15,36 @@ void ft_ent_filter(t_list **ent, int opts) { if (!(opts & OPTS_LA)) - ft_lst_delif(ent, ".", &ft_lsdata_cmp0, &ft_ent_free); + { + if (!(opts & OPTS_UA)) + ft_lst_delif(ent, ".", &ft_lsdata_cmp0, &ft_ent_free); + else + ft_lst_delif(ent, ".", &ft_lsdata_cmpA, &ft_ent_free); + } } void ft_ent_sort(t_list **ent, int opts) { int (*ft_sort)(); - if (opts & OPTS_LT) - ft_sort = &ft_lsdata_cmp_time; - else - ft_sort = &ft_lsdata_cmp_name; - ft_lst_sort(ent, ft_sort); + ft_lst_reverse(ent); + ft_sort = &ft_lsdata_cmp_name; + if (opts & OPTS_LF) + return ; + if (opts & OPTS_US) + ft_sort = &ft_lsdata_cmp_size; + else if (opts & OPTS_LT) + { + if (opts & OPTS_LC) + ft_sort = &ft_cmp_ctime; + else if (opts & OPTS_LU) + ft_sort = &ft_cmp_atime; + else if (opts & OPTS_UU) + ft_sort = &ft_cmp_btime; + else + ft_sort = &ft_cmp_mtime; + } + ft_lstsort(ent, ft_sort); if (opts & OPTS_LR) ft_lst_reverse(ent); } @@ -43,14 +61,18 @@ void ft_ent_print(t_list *ent, int *opts, t_lsdata *topdir, t_list *nextdir) if (ent) { if (*opts & OPTS_LL) - ft_ls_long(ent, topdir); + ft_ls_long(ent, topdir, *opts); else - ft_ls_short(ent); + ft_ls_short(ent, topdir, *opts); + } + else if (*opts & OPTS_ERR_A) + { + *opts &= ~OPTS_ERR_A; + ft_error_access(topdir->path); } - /* else */ - /* ft_error_access(topdir->path); */ if ((!topdir && nextdir && ent) || (topdir && nextdir) - || (ent && ((*opts & OPTS_UR) && ft_ent_has_dir(ent)))) + || (((*opts & OPTS_UR) + && ent && ft_ent_has_dir(ent)))) ft_putchar('\n'); } diff --git a/ls/src/lib_error.c b/ls/src/lib_error.c index bec542f6..1c966e54 100644 --- a/ls/src/lib_error.c +++ b/ls/src/lib_error.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:57:43 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:58:14 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 14:04:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,22 @@ void ft_error_option(char c) void ft_error_access(char *s) { - ft_dprintf(2, LS_MSG_ACC_ERR, s); + /* ft_dprintf(2, LS_MSG_ACC_ERR, s); */ + /* ft_printf("strerror:%s\n", strerror(errno)); */ + ft_dprintf(2, "ls: "); + perror(s); } void ft_error_dir(char *s) { - ft_dprintf(2, LS_MSG_FILE_ERR, s); + /* ft_dprintf(2, LS_MSG_FILE_ERR, s); */ + /* ft_printf("strerror:%s\n", strerror(errno)); */ + ft_dprintf(2, "ls: "); + if (*s) + perror(s); + else + { + perror("fts_open"); + exit(1); + } } diff --git a/ls/src/lib_ls_long.c b/ls/src/lib_ls_long.c index 4526243f..af478e21 100644 --- a/ls/src/lib_ls_long.c +++ b/ls/src/lib_ls_long.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:59:51 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:07:09 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:50:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,19 +33,32 @@ int ft_ls_long_middle(struct stat *stat, t_pads *pads) return (0); } -void ft_ls_long_date(struct stat *stat) +void ft_ls_long_date(struct stat *stat, int opts) { char *date; char *day; char *month; char *time; + time_t st_time; - date = ctime(&stat->st_mtime); + if (opts & OPTS_LC) + st_time = stat->st_ctime; + else if (opts & OPTS_LU) + st_time = stat->st_atime; + else if (opts & OPTS_UU) + st_time = stat->st_birthtime; + else + st_time = stat->st_mtime; + date = ctime(&st_time); + /* ft_printf("\nctime is:%s\n", date); */ month = ft_strsub(date, 4, 3); day = ft_strsub(date, 8, 2); - time = ft_time_isrecent(stat->st_mtime) - ? ft_strsub(date, 11, 5) - : ft_strsub(date, 20, 4); + if (ft_time_isrecent(st_time)) + time = ft_strsub(date, 11, 5); + else if (ft_isdigit(date[20])) + time = ft_strsub(date, 20, 4); + else + time = ft_strsub(date, 23, 6); ft_printf(" %s %s %5s", month, day, time); free(month); free(day); diff --git a/ls/src/lib_ls_long2.c b/ls/src/lib_ls_long2.c index c30b63b2..9c5d2f79 100644 --- a/ls/src/lib_ls_long2.c +++ b/ls/src/lib_ls_long2.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:01:01 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:19:55 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 16:19:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,11 +58,9 @@ int ft_ls_long_xattr(mode_t m, char *path) x = ' '; n = 0; - if (!(m & (S_IFCHR | S_IFBLK))) + if (!S_ISBLK(m) && !S_ISCHR(m)) if ((n = ft_xattr_count(path)) == -1) - { ; - } if (n > 0) x = '@'; ft_putchar(x); diff --git a/ls/src/lib_lsdata.c b/ls/src/lib_lsdata.c index 1af38e63..b22a861a 100644 --- a/ls/src/lib_lsdata.c +++ b/ls/src/lib_lsdata.c @@ -6,23 +6,25 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:59:09 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:40:06 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:49:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ls.h" -void ft_lsdata_filename(t_lsdata *data) +void ft_lsdata_filename(t_lsdata *data, t_lsdata *topdir, int opts) { struct dirent *dirent; dirent = data->dirent; if (data->path) - ft_printf("%s", ft_path_notdir(data->path)); + ft_printf("%s", topdir ? ft_path_notdir(data->path) : data->path); else if (dirent && *dirent->d_name) ft_printf("%s", dirent->d_name); else ft_printf("noname!"); + if (opts & OPTS_LP && S_ISDIR(data->stat.st_mode)) + ft_putchar('/'); } int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2) @@ -30,14 +32,6 @@ int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2) return (ft_strcmp(dat1->path, dat2->path)); } -int ft_lsdata_cmp_time(t_lsdata *dat1, t_lsdata *dat2) -{ - if (dat2->stat.st_mtime - dat1->stat.st_mtime) - return (dat2->stat.st_mtime - dat1->stat.st_mtime); - else - return (ft_strcmp(dat1->path, dat2->path)); -} - int ft_lsdata_cmp0(t_lsdata *data, char *dataref) { char *filename; @@ -48,3 +42,25 @@ int ft_lsdata_cmp0(t_lsdata *data, char *dataref) filename = data->dirent->d_name; return (*filename != *dataref); } + +int ft_lsdata_cmpA(t_lsdata *data, char *dataref) +{ + char *filename; + + (void)dataref; + if (data->path) + filename = ft_path_notdir(data->path); + else + filename = data->dirent->d_name; + if (!ft_strcmp(filename, ".") || !ft_strcmp(filename, "..")) + return (0); + return (1); +} + +int ft_lsdata_cmp_size(t_lsdata *dat1, t_lsdata *dat2) +{ + if (dat2->stat.st_size - dat1->stat.st_size) + return (dat2->stat.st_size - dat1->stat.st_size); + else + return (ft_strcmp(dat1->path, dat2->path)); +} diff --git a/ls/src/lib_parse.c b/ls/src/lib_parse.c index 11d36c69..1745e6a0 100644 --- a/ls/src/lib_parse.c +++ b/ls/src/lib_parse.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:02:46 by jhalford #+# #+# */ -/* Updated: 2016/11/22 17:01:37 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:46:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_ls.h" -static void ft_ls_parse_files(int ac, char **av, t_list **dir, t_list **ent) +static void ft_ls_parse_files(int ac, char **av, int opts, t_list **dir, t_list **ent) { t_lsdata data; int i; @@ -21,16 +21,25 @@ static void ft_ls_parse_files(int ac, char **av, t_list **dir, t_list **ent) i = -1; while (++i < ac) { - if (lstat(av[i], &data.stat) < 0) + if (stat(av[i], &data.stat) < 0) { - ft_error_dir(av[i]); - continue ; + if (lstat(av[i], &data.stat) < 0) + { + ft_error_dir(av[i]); + continue ; + } } + if (opts & OPTS_LL || !S_ISDIR(data.stat.st_mode)) + if (lstat(av[i], &data.stat) < 0) + { + ft_error_dir(av[i]); + continue ; + } data.path = ft_strdup(av[i]); - if (S_ISDIR(data.stat.st_mode)) - ft_lstadd(dir, ft_lstnew(&data, sizeof(data))); - else + if (opts & OPTS_LD || !S_ISDIR(data.stat.st_mode)) ft_lstadd(ent, ft_lstnew(&data, sizeof(data))); + else + ft_lstadd(dir, ft_lstnew(&data, sizeof(data))); } } @@ -44,17 +53,57 @@ static int ft_getopts(char *str) while (str[i]) { if (str[i] == 'l') + { opts |= OPTS_LL; + opts &= ~OPTS_ONE; + } else if (str[i] == '1') + { opts |= OPTS_ONE; + opts &= ~OPTS_LL; + } else if (str[i] == 'a') opts |= OPTS_LA; + else if (str[i] == 'c') + { + opts &= ~TIME_MASK; + opts |= OPTS_LC; + } + else if (str[i] == 'f') + { + opts |= OPTS_LF; + opts |= OPTS_LA; + } else if (str[i] == 't') opts |= OPTS_LT; else if (str[i] == 'r') opts |= OPTS_LR; + else if (str[i] == 'd') + { + opts &= ~OPTS_UR; + opts |= OPTS_LD; + } + else if (str[i] == 'p') + opts |= OPTS_LP; + else if (str[i] == 'u') + { + opts &= ~TIME_MASK; + opts |= OPTS_LU; + } + else if (str[i] == 'A') + opts |= OPTS_UA; else if (str[i] == 'R') - opts |= OPTS_UR; + { + if (!(opts & OPTS_LD)) + opts |= OPTS_UR; + } + else if (str[i] == 'U') + { + opts &= ~TIME_MASK; + opts |= OPTS_UU; + } + else if (str[i] == 'S') + opts |= OPTS_US; else { ft_error_option(str[i]); @@ -97,9 +146,10 @@ int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent) opts = 0; i = ft_ls_parse_options(ac, av, &opts); opts |= (ac - i > 1) ? OPTS_HEAD : 0; + ft_sstrsort(av + i, &ft_strcmp); if (i == ac) - ft_ls_parse_files(1, (char*[2]){"."}, dir, ent); + ft_ls_parse_files(1, (char*[2]){"."}, opts,dir, ent); else - ft_ls_parse_files(ac - i, av + i, dir, ent); + ft_ls_parse_files(ac - i, av + i, opts, dir, ent); return (opts); } diff --git a/ls/src/lib_time.c b/ls/src/lib_time.c new file mode 100644 index 00000000..2b5ed97f --- /dev/null +++ b/ls/src/lib_time.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lib_time.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/23 16:49:05 by jhalford #+# #+# */ +/* Updated: 2016/11/23 18:46:16 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_ls.h" + +int ft_cmp_mtime(t_lsdata *dat1, t_lsdata *dat2) +{ + if (dat2->stat.st_mtime - dat1->stat.st_mtime) + return (dat2->stat.st_mtime - dat1->stat.st_mtime); + else + return (ft_strcmp(dat1->path, dat2->path)); +} + +int ft_cmp_ctime(t_lsdata *dat1, t_lsdata *dat2) +{ + if (dat2->stat.st_ctime - dat1->stat.st_ctime) + return (dat2->stat.st_ctime - dat1->stat.st_ctime); + else + return (ft_strcmp(dat1->path, dat2->path)); +} + +int ft_cmp_atime(t_lsdata *dat1, t_lsdata *dat2) +{ + if (dat2->stat.st_atime - dat1->stat.st_atime) + return (dat2->stat.st_atime - dat1->stat.st_atime); + else + return (ft_strcmp(dat1->path, dat2->path)); +} + +int ft_cmp_btime(t_lsdata *dat1, t_lsdata *dat2) +{ + if (dat2->stat.st_birthtime - dat1->stat.st_birthtime) + return (dat2->stat.st_birthtime - dat1->stat.st_birthtime); + else + return (ft_strcmp(dat1->path, dat2->path)); +} diff --git a/ls/src/main.c b/ls/src/main.c index 9210898b..60c53f46 100644 --- a/ls/src/main.c +++ b/ls/src/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:00:15 by jhalford #+# #+# */ -/* Updated: 2016/11/22 16:47:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 18:20:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */