many bonus' done, need to fix norm now xD
This commit is contained in:
parent
c23ee4d832
commit
031045fbe3
22 changed files with 404 additions and 250 deletions
21
ls/.tags
21
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)$/
|
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)$/
|
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_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_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)$/
|
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_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_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_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 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)$/
|
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_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_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_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_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)$/
|
||||||
ft_ls_long_xattr src/lib_ls_long2.c /^int ft_ls_long_xattr(mode_t m, char *path)$/
|
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 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_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_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_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_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)$/
|
ft_lsdata_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data, t_lsdata */
|
||||||
|
|
|
||||||
185
ls/Session.vim
185
ls/Session.vim
|
|
@ -8,28 +8,28 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
||||||
let s:wipebuf = bufnr('%')
|
let s:wipebuf = bufnr('%')
|
||||||
endif
|
endif
|
||||||
set shortmess=aoO
|
set shortmess=aoO
|
||||||
badd +116 src/lib_ls_long2.c
|
badd +62 src/lib_ls_long2.c
|
||||||
badd +26 src/ft_ls_long.c
|
badd +37 src/ft_ls_long.c
|
||||||
badd +1 includes/ft_ls.h
|
badd +82 includes/ft_ls.h
|
||||||
badd +60 ~/.tmux.conf
|
badd +60 ~/.tmux.conf
|
||||||
badd +29 src/lib_ls_long.c
|
badd +35 src/lib_ls_long.c
|
||||||
badd +35 src/lib_lsdata.c
|
badd +29 src/lib_lsdata.c
|
||||||
badd +34 src/lib_parse.c
|
badd +39 src/lib_parse.c
|
||||||
badd +22 libft/src/ft_printf/lib_pad.c
|
badd +22 libft/src/ft_printf/lib_pad.c
|
||||||
badd +19 libft/src/ft_printf/lib_pad_sharp.c
|
badd +19 libft/src/ft_printf/lib_pad_sharp.c
|
||||||
badd +14 libft/src/lst/ft_lst_filter.c
|
badd +14 libft/src/lst/ft_lst_filter.c
|
||||||
badd +14 src/lib_dirents.c
|
badd +14 src/lib_dirents.c
|
||||||
badd +21 src/main.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 +23 src/ft_ent_free.c
|
||||||
badd +1 Makefile
|
badd +17 Makefile
|
||||||
badd +21 src/lib_error.c
|
badd +38 src/lib_error.c
|
||||||
badd +32 src/lib_dirs.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 +69 libft/src/ft_printf/ft_printf.c
|
||||||
badd +46 libft/includes/ft_printf.h
|
badd +46 libft/includes/ft_printf.h
|
||||||
badd +2 libft/src/printing/ft_putstr_fd.c
|
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 +2 libft/src/ft_printf/lib_fmt.c
|
||||||
badd +1 src/.lib_dirents.c.swo
|
badd +1 src/.lib_dirents.c.swo
|
||||||
badd +1 ft_ls
|
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 +32 libft/src/lst/ft_lst_delif.c
|
||||||
badd +22 libft/src/lst/ft_lstdelone.c
|
badd +22 libft/src/lst/ft_lstdelone.c
|
||||||
badd +25 libft/src/lst/ft_lst_removeif.c
|
badd +25 libft/src/lst/ft_lst_removeif.c
|
||||||
badd +42 ~/.vimrc
|
badd +1 ~/.vimrc
|
||||||
badd +12 src/ft_ent_has_dir.c
|
badd +24 src/ft_ent_has_dir.c
|
||||||
badd +35 src/ft_ent_get_dirs.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 +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 +22 libft/src/str/ft_strsub.c
|
||||||
badd +1 libft/Makefile
|
badd +1 libft/Makefile
|
||||||
badd +14 libft/src/btree/btree_print.c
|
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 +13 libft/src/str/ft_strinsert.c
|
||||||
badd +20 libft/src/str/ft_strdel.c
|
badd +20 libft/src/str/ft_strdel.c
|
||||||
badd +22 libft/src/str/ft_strjoin.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
|
args src/lib_ls_long2.c
|
||||||
edit includes/ft_ls.h
|
edit includes/ft_ls.h
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
|
|
@ -65,8 +74,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 98 + 98) / 196)
|
exe 'vert 1resize ' . ((&columns * 90 + 102) / 204)
|
||||||
exe 'vert 2resize ' . ((&columns * 97 + 98) / 196)
|
exe 'vert 2resize ' . ((&columns * 113 + 102) / 204)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -77,15 +86,15 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
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
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
96
|
28
|
||||||
normal! 029l
|
normal! 025l
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
argglobal
|
||||||
edit Makefile
|
edit src/main.c
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
setlocal fmr={{{,}}}
|
setlocal fmr={{{,}}}
|
||||||
|
|
@ -95,16 +104,60 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
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
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
17
|
25
|
||||||
normal! 011l
|
normal! 01l
|
||||||
wincmd w
|
wincmd w
|
||||||
exe 'vert 1resize ' . ((&columns * 98 + 98) / 196)
|
exe 'vert 1resize ' . ((&columns * 90 + 102) / 204)
|
||||||
exe 'vert 2resize ' . ((&columns * 97 + 98) / 196)
|
exe 'vert 2resize ' . ((&columns * 113 + 102) / 204)
|
||||||
tabedit src/main.c
|
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
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
wincmd _ | wincmd |
|
||||||
vsplit
|
vsplit
|
||||||
|
|
@ -114,51 +167,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 98 + 98) / 196)
|
exe 'vert 1resize ' . ((&columns * 102 + 102) / 204)
|
||||||
exe 'vert 2resize ' . ((&columns * 97 + 98) / 196)
|
exe 'vert 2resize ' . ((&columns * 101 + 102) / 204)
|
||||||
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
|
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -174,7 +184,28 @@ if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
24
|
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
|
tabedit src/lib_ent.c
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
set nosplitbelow
|
set nosplitbelow
|
||||||
|
|
@ -191,13 +222,13 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
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
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
49
|
32
|
||||||
normal! 01l
|
normal! 019l
|
||||||
tabnext 4
|
tabnext 5
|
||||||
if exists('s:wipebuf')
|
if exists('s:wipebuf')
|
||||||
silent exe 'bwipe ' . s:wipebuf
|
silent exe 'bwipe ' . s:wipebuf
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 15:10:03 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_LEGAL_OPTS "larRt"
|
||||||
# define LS_MSG_ILLEGAL_OPT "ft_ls: illegal option -- %c\n"
|
# define LS_MSG_ILLEGAL_OPT "ft_ls: illegal option -- %c\n"
|
||||||
# define LS_MSG_USAGE "usage: ls [-%s] [file ...]\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_FILE_ERR "ls: %s: No such file or directory\n"
|
||||||
# define LS_MSG_ACC_ERR "ls: %s: Permission Denied\n"
|
# define LS_MSG_ACC_ERR "ls: %s: Permission denied\n"
|
||||||
|
|
||||||
# define OPTS_LL 0x0001
|
# define OPTS_LA 0x0000001
|
||||||
# define OPTS_LA 0x0002
|
# define OPTS_LC 0x0000002
|
||||||
# define OPTS_LR 0x0004
|
# define OPTS_LD 0x0000004
|
||||||
# define OPTS_UR 0x0008
|
# define OPTS_LF 0x0000008
|
||||||
# define OPTS_LT 0x0010
|
# define OPTS_LL 0x0000010
|
||||||
# define OPTS_ONE 0x0020
|
# define OPTS_LP 0x0000020
|
||||||
# define OPTS_HEAD 0x1000
|
# 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 "libft.h"
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
|
# include <stdio.h>
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
|
|
@ -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_dirs(t_list *dir, int opts);
|
||||||
void ft_ls_files(t_list **ent, t_list **dir, t_lsdata *topdir, 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_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_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_filter(t_list **ent, int opts);
|
||||||
void ft_ent_sort(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_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(t_list *ent, t_lsdata *topdir, int opts);
|
||||||
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);
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -88,7 +106,7 @@ void ft_ls_long_type(mode_t m);
|
||||||
void ft_ls_long_rights(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_xattr(mode_t m, char *path);
|
||||||
int ft_ls_long_middle(struct stat *stat, t_pads *pads);
|
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);
|
int ft_ls_long_lnk(t_lsdata *data);
|
||||||
|
|
||||||
void ft_error_option(char c);
|
void ft_error_option(char c);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:49:04 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);
|
int ft_addrcmp(void *a, void *b);
|
||||||
|
|
||||||
char **ft_sstradd(char **list, char *new);
|
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);
|
void ft_sstrprint(char **list, char sep);
|
||||||
char **ft_sstrdup(char **list);
|
char **ft_sstrdup(char **list);
|
||||||
void ft_sstrdel(char **sstr, int index);
|
void ft_sstrdel(char **sstr, int index);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:27:46 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);
|
t_list *ft_lstnew_range(int a, int b);
|
||||||
void ft_lsteadd(t_list **alst, t_list *new);
|
void ft_lsteadd(t_list **alst, t_list *new);
|
||||||
void ft_lstnadd(t_list **alst, t_list *new, int n);
|
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)());
|
void ft_lst_print(t_list *list, void (*printer)());
|
||||||
int ft_lstsize(t_list *lst);
|
int ft_lstsize(t_list *lst);
|
||||||
t_list *ft_lstlast(t_list *lst);
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_sort.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,44 +6,33 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:58 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"
|
#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 *tmp;
|
||||||
|
t_list *tmp2;
|
||||||
|
|
||||||
tmp = (*current)->next->next;
|
indirect = begin_list;
|
||||||
(*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;
|
|
||||||
if (!*begin_list)
|
if (!*begin_list)
|
||||||
return ;
|
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)
|
tmp = *indirect;
|
||||||
last->next = current->next;
|
tmp2 = (*indirect)->next;
|
||||||
else
|
(*indirect)->next = (*indirect)->next->next;
|
||||||
*begin_list = current->next;
|
*indirect = tmp2;
|
||||||
ft_list_swap(¤t);
|
(*indirect)->next = tmp;
|
||||||
current = *begin_list;
|
indirect = begin_list;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
indirect = &(*indirect)->next;
|
||||||
last = current;
|
|
||||||
current = current->next ? current->next : current;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:45:07 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;
|
char *ret;
|
||||||
|
|
||||||
ret = path;
|
ret = path;
|
||||||
if ((slash = ft_strrchr(path, '/')))
|
if ((slash = ft_strrchr(path, '/')) && slash != path)
|
||||||
ret = slash + 1;
|
ret = slash + 1;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,19 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 18:03:37 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"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_sstrsort(char **list, int size, int (*cmp)())
|
void ft_sstrsort(char **list, int (*cmp)())
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < size - 1)
|
while (list[i] && list[i + 1])
|
||||||
{
|
{
|
||||||
if ((*cmp)(list[i], list[i + 1]) > 0)
|
if ((*cmp)(list[i], list[i + 1]) > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,33 +6,36 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:58:49 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"
|
#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;
|
t_list *ent;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
t_lsdata data;
|
t_lsdata data;
|
||||||
DIR *stream;
|
DIR *stream;
|
||||||
|
char *prepath;
|
||||||
|
|
||||||
ent = NULL;
|
ent = NULL;
|
||||||
if (!(stream = opendir(topdir->path)))
|
if (!(stream = opendir(topdir->path)))
|
||||||
{
|
{
|
||||||
ft_error_access(topdir->path);
|
*opts |= OPTS_ERR_A;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
prepath = ft_strjoin(topdir->path, "/");
|
||||||
while ((dirent = readdir(stream)))
|
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);
|
lstat(data.path, &data.stat);
|
||||||
data.dirent = ft_memalloc(sizeof(*dirent) + 1);
|
data.dirent = ft_memalloc(sizeof(*dirent) + 1);
|
||||||
ft_memcpy(data.dirent, dirent, sizeof(*dirent));
|
ft_memcpy(data.dirent, dirent, sizeof(*dirent));
|
||||||
ft_lstadd(&ent, ft_lstnew(&data, sizeof(data)));
|
ft_lstadd(&ent, ft_lstnew(&data, sizeof(data)));
|
||||||
}
|
}
|
||||||
|
ft_strdel(&prepath);
|
||||||
closedir(stream);
|
closedir(stream);
|
||||||
return (ent);
|
return (ent);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/16 15:42:54 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:57:21 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;
|
tmp = dir;
|
||||||
dir = dir->next;
|
dir = dir->next;
|
||||||
ft_lstdel(&ent, &ft_ent_free);
|
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_ls_files(&ent, &dir, dirdata, &opts);
|
||||||
ft_lstdelone(&tmp, &ft_ent_free);
|
ft_lstdelone(&tmp, &ft_ent_free);
|
||||||
if (opts & OPTS_UR)
|
if (opts & OPTS_UR)
|
||||||
|
|
@ -44,6 +44,7 @@ void ft_ls_files(t_list **ent, t_list **dir, t_lsdata *topdir, int *opts)
|
||||||
{
|
{
|
||||||
if (ent)
|
if (ent)
|
||||||
{
|
{
|
||||||
|
if (topdir)
|
||||||
ft_ent_filter(ent, *opts);
|
ft_ent_filter(ent, *opts);
|
||||||
ft_ent_sort(ent, *opts);
|
ft_ent_sort(ent, *opts);
|
||||||
ft_ent_print(*ent, opts, topdir, *dir);
|
ft_ent_print(*ent, opts, topdir, *dir);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:58:05 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"
|
#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;
|
t_pads pads;
|
||||||
|
|
||||||
|
|
@ -22,14 +22,14 @@ int ft_ls_long(t_list *ent, t_lsdata *topdir)
|
||||||
return (1);
|
return (1);
|
||||||
while (ent)
|
while (ent)
|
||||||
{
|
{
|
||||||
if (ft_ls_long_print(ent, pads))
|
if (ft_ls_long_print(ent, topdir, pads, opts))
|
||||||
return (1);
|
return (1);
|
||||||
ent = ent->next;
|
ent = ent->next;
|
||||||
}
|
}
|
||||||
return (0);
|
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;
|
t_lsdata *data;
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
|
@ -45,9 +45,9 @@ int ft_ls_long_print(t_list *ent, t_pads pads)
|
||||||
return (1);
|
return (1);
|
||||||
if (ft_ls_long_middle(&stat, &pads))
|
if (ft_ls_long_middle(&stat, &pads))
|
||||||
return (1);
|
return (1);
|
||||||
ft_ls_long_date(&stat);
|
ft_ls_long_date(&stat, opts);
|
||||||
ft_printf(" ");
|
ft_printf(" ");
|
||||||
ft_lsdata_filename(data);
|
ft_lsdata_filename(data, topdir, opts);
|
||||||
if (ft_ls_long_lnk(data))
|
if (ft_ls_long_lnk(data))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,17 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:56:28 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"
|
#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)
|
while (ent)
|
||||||
{
|
{
|
||||||
ft_lsdata_filename(ent->content);
|
ft_lsdata_filename(ent->content, topdir, opts);
|
||||||
ft_printf("\n");
|
ft_printf("\n");
|
||||||
ent = ent->next;
|
ent = ent->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 15:00:05 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)
|
void ft_ent_filter(t_list **ent, int opts)
|
||||||
{
|
{
|
||||||
if (!(opts & OPTS_LA))
|
if (!(opts & OPTS_LA))
|
||||||
|
{
|
||||||
|
if (!(opts & OPTS_UA))
|
||||||
ft_lst_delif(ent, ".", &ft_lsdata_cmp0, &ft_ent_free);
|
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)
|
void ft_ent_sort(t_list **ent, int opts)
|
||||||
{
|
{
|
||||||
int (*ft_sort)();
|
int (*ft_sort)();
|
||||||
|
|
||||||
if (opts & OPTS_LT)
|
ft_lst_reverse(ent);
|
||||||
ft_sort = &ft_lsdata_cmp_time;
|
|
||||||
else
|
|
||||||
ft_sort = &ft_lsdata_cmp_name;
|
ft_sort = &ft_lsdata_cmp_name;
|
||||||
ft_lst_sort(ent, ft_sort);
|
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)
|
if (opts & OPTS_LR)
|
||||||
ft_lst_reverse(ent);
|
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 (ent)
|
||||||
{
|
{
|
||||||
if (*opts & OPTS_LL)
|
if (*opts & OPTS_LL)
|
||||||
ft_ls_long(ent, topdir);
|
ft_ls_long(ent, topdir, *opts);
|
||||||
else
|
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)
|
if ((!topdir && nextdir && ent)
|
||||||
|| (topdir && nextdir)
|
|| (topdir && nextdir)
|
||||||
|| (ent && ((*opts & OPTS_UR) && ft_ent_has_dir(ent))))
|
|| (((*opts & OPTS_UR)
|
||||||
|
&& ent && ft_ent_has_dir(ent))))
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:57:43 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)
|
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)
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:59:51 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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_ls_long_date(struct stat *stat)
|
void ft_ls_long_date(struct stat *stat, int opts)
|
||||||
{
|
{
|
||||||
char *date;
|
char *date;
|
||||||
char *day;
|
char *day;
|
||||||
char *month;
|
char *month;
|
||||||
char *time;
|
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);
|
month = ft_strsub(date, 4, 3);
|
||||||
day = ft_strsub(date, 8, 2);
|
day = ft_strsub(date, 8, 2);
|
||||||
time = ft_time_isrecent(stat->st_mtime)
|
if (ft_time_isrecent(st_time))
|
||||||
? ft_strsub(date, 11, 5)
|
time = ft_strsub(date, 11, 5);
|
||||||
: ft_strsub(date, 20, 4);
|
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);
|
ft_printf(" %s %s %5s", month, day, time);
|
||||||
free(month);
|
free(month);
|
||||||
free(day);
|
free(day);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 15:01:01 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 = ' ';
|
x = ' ';
|
||||||
n = 0;
|
n = 0;
|
||||||
if (!(m & (S_IFCHR | S_IFBLK)))
|
if (!S_ISBLK(m) && !S_ISCHR(m))
|
||||||
if ((n = ft_xattr_count(path)) == -1)
|
if ((n = ft_xattr_count(path)) == -1)
|
||||||
{
|
|
||||||
;
|
;
|
||||||
}
|
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
x = '@';
|
x = '@';
|
||||||
ft_putchar(x);
|
ft_putchar(x);
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,25 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 14:59:09 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"
|
#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;
|
struct dirent *dirent;
|
||||||
|
|
||||||
dirent = data->dirent;
|
dirent = data->dirent;
|
||||||
if (data->path)
|
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)
|
else if (dirent && *dirent->d_name)
|
||||||
ft_printf("%s", dirent->d_name);
|
ft_printf("%s", dirent->d_name);
|
||||||
else
|
else
|
||||||
ft_printf("noname!");
|
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)
|
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));
|
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)
|
int ft_lsdata_cmp0(t_lsdata *data, char *dataref)
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
@ -48,3 +42,25 @@ int ft_lsdata_cmp0(t_lsdata *data, char *dataref)
|
||||||
filename = data->dirent->d_name;
|
filename = data->dirent->d_name;
|
||||||
return (*filename != *dataref);
|
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));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 15:02:46 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"
|
#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;
|
t_lsdata data;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -21,16 +21,25 @@ static void ft_ls_parse_files(int ac, char **av, t_list **dir, t_list **ent)
|
||||||
i = -1;
|
i = -1;
|
||||||
while (++i < ac)
|
while (++i < ac)
|
||||||
{
|
{
|
||||||
|
if (stat(av[i], &data.stat) < 0)
|
||||||
|
{
|
||||||
|
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)
|
if (lstat(av[i], &data.stat) < 0)
|
||||||
{
|
{
|
||||||
ft_error_dir(av[i]);
|
ft_error_dir(av[i]);
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
data.path = ft_strdup(av[i]);
|
data.path = ft_strdup(av[i]);
|
||||||
if (S_ISDIR(data.stat.st_mode))
|
if (opts & OPTS_LD || !S_ISDIR(data.stat.st_mode))
|
||||||
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
|
||||||
else
|
|
||||||
ft_lstadd(ent, ft_lstnew(&data, sizeof(data)));
|
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])
|
while (str[i])
|
||||||
{
|
{
|
||||||
if (str[i] == 'l')
|
if (str[i] == 'l')
|
||||||
|
{
|
||||||
opts |= OPTS_LL;
|
opts |= OPTS_LL;
|
||||||
|
opts &= ~OPTS_ONE;
|
||||||
|
}
|
||||||
else if (str[i] == '1')
|
else if (str[i] == '1')
|
||||||
|
{
|
||||||
opts |= OPTS_ONE;
|
opts |= OPTS_ONE;
|
||||||
|
opts &= ~OPTS_LL;
|
||||||
|
}
|
||||||
else if (str[i] == 'a')
|
else if (str[i] == 'a')
|
||||||
opts |= OPTS_LA;
|
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')
|
else if (str[i] == 't')
|
||||||
opts |= OPTS_LT;
|
opts |= OPTS_LT;
|
||||||
else if (str[i] == 'r')
|
else if (str[i] == 'r')
|
||||||
opts |= OPTS_LR;
|
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')
|
else if (str[i] == 'R')
|
||||||
|
{
|
||||||
|
if (!(opts & OPTS_LD))
|
||||||
opts |= OPTS_UR;
|
opts |= OPTS_UR;
|
||||||
|
}
|
||||||
|
else if (str[i] == 'U')
|
||||||
|
{
|
||||||
|
opts &= ~TIME_MASK;
|
||||||
|
opts |= OPTS_UU;
|
||||||
|
}
|
||||||
|
else if (str[i] == 'S')
|
||||||
|
opts |= OPTS_US;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_error_option(str[i]);
|
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;
|
opts = 0;
|
||||||
i = ft_ls_parse_options(ac, av, &opts);
|
i = ft_ls_parse_options(ac, av, &opts);
|
||||||
opts |= (ac - i > 1) ? OPTS_HEAD : 0;
|
opts |= (ac - i > 1) ? OPTS_HEAD : 0;
|
||||||
|
ft_sstrsort(av + i, &ft_strcmp);
|
||||||
if (i == ac)
|
if (i == ac)
|
||||||
ft_ls_parse_files(1, (char*[2]){"."}, dir, ent);
|
ft_ls_parse_files(1, (char*[2]){"."}, opts,dir, ent);
|
||||||
else
|
else
|
||||||
ft_ls_parse_files(ac - i, av + i, dir, ent);
|
ft_ls_parse_files(ac - i, av + i, opts, dir, ent);
|
||||||
return (opts);
|
return (opts);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
45
ls/src/lib_time.c
Normal file
45
ls/src/lib_time.c
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_time.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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));
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 15:00:15 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue