leak problems and days work
This commit is contained in:
parent
b0bb8de22c
commit
f8d3967a8d
15 changed files with 337 additions and 169 deletions
16
ls/.tags
16
ls/.tags
|
|
@ -1,15 +1,17 @@
|
|||
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_ent_filter src/lib_dirents.c /^void ft_ent_filter(t_list **ent, char *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_get_dirs src/lib_dirents.c /^t_list *ft_ent_get_dirs(t_list *ent)$/
|
||||
ft_ent_print src/lib_dirents.c /^void ft_ent_print(t_list *ent, char *opts, t_lsdat/
|
||||
ft_ent_sort src/lib_dirents.c /^void ft_ent_sort(t_list **ent, char *opts)$/
|
||||
ft_ent_get_dirs src/ft_ent_get_dirs.c /^t_list *ft_ent_get_dirs(t_list **ent)$/
|
||||
ft_ent_has_dir src/ft_ent_has_dir.c /^int ft_ent_has_dir(t_list *ent)$/
|
||||
ft_ent_print src/lib_ent.c /^void ft_ent_print(t_list *ent, int *opts, t_lsdata/
|
||||
ft_ent_sort src/lib_ent.c /^void ft_ent_sort(t_list **ent, int opts)$/
|
||||
ft_error_dir src/lib_error.c /^void ft_error_dir(char *s)$/
|
||||
ft_error_option src/lib_error.c /^void ft_error_option(char c)$/
|
||||
ft_ls_dirs src/ft_ls.c /^void ft_ls_dirs(t_list *dir, char *opts)$/
|
||||
ft_ls_files src/ft_ls.c /^void ft_ls_files(t_list *ent, t_list *dir, char *o/
|
||||
ft_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, int opt/
|
||||
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_lnk src/lib_ls_long2.c /^int ft_ls_long_lnk(t_lsdata *data)$/
|
||||
|
|
@ -20,7 +22,7 @@ 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 /^char *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_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)$/
|
||||
|
|
|
|||
179
ls/Session.vim
179
ls/Session.vim
|
|
@ -8,26 +8,48 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
|||
let s:wipebuf = bufnr('%')
|
||||
endif
|
||||
set shortmess=aoO
|
||||
badd +103 src/lib_ls_long2.c
|
||||
badd +98 src/lib_ls_long2.c
|
||||
badd +27 src/ft_ls_long.c
|
||||
badd +45 includes/ft_ls.h
|
||||
badd +15 includes/ft_ls.h
|
||||
badd +60 ~/.tmux.conf
|
||||
badd +47 src/lib_ls_long.c
|
||||
badd +52 src/lib_ls_long.c
|
||||
badd +35 src/lib_lsdata.c
|
||||
badd +59 src/lib_parse.c
|
||||
badd +76 src/lib_parse.c
|
||||
badd +22 libft/src/ft_printf/lib_pad.c
|
||||
badd +19 libft/src/ft_printf/lib_pad_sharp.c
|
||||
badd +9 libft/src/lst/ft_lst_filter.c
|
||||
badd +30 src/lib_dirents.c
|
||||
badd +26 src/main.c
|
||||
badd +14 src/lib_dirents.c
|
||||
badd +21 src/main.c
|
||||
badd +32 src/ft_ls.c
|
||||
badd +23 src/ft_ent_free.c
|
||||
badd +21 src/ft_ent_free.c
|
||||
badd +1 Makefile
|
||||
badd +14 src/lib_error.c
|
||||
badd +16 src/lib_error.c
|
||||
badd +32 src/lib_dirs.c
|
||||
badd +29 src/ft_dir_get_ents.c
|
||||
badd +19 src/ft_dir_get_ents.c
|
||||
badd +33 libft/src/ft_printf/ft_printf.c
|
||||
badd +43 libft/includes/ft_printf.h
|
||||
badd +2 libft/src/printing/ft_putstr_fd.c
|
||||
badd +11 libft/includes/libft.h
|
||||
badd +2 libft/src/ft_printf/lib_fmt.c
|
||||
badd +0 src/.lib_dirents.c.swo
|
||||
badd +1 ft_ls
|
||||
badd +1 libft/src/dlst/ft_dlstdel.c
|
||||
badd +19 libft/src/lst/ft_lstdel.c
|
||||
badd +21 libft/src/path/ft_path_notdir.c
|
||||
badd +0 libft/src/mem/ft_memcpy.c
|
||||
badd +19 libft/src/mem/ft_memdel.c
|
||||
badd +11 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 +15 src/ft_ent_get_dirs.c
|
||||
badd +17 src/lib_ent.c
|
||||
badd +11 .Makefile.swp
|
||||
badd +18 ~/dotfiles/vim.symlink/plugins.vim
|
||||
badd +22 libft/src/str/ft_strsub.c
|
||||
args src/lib_ls_long2.c
|
||||
edit src/main.c
|
||||
edit includes/ft_ls.h
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
|
|
@ -37,8 +59,8 @@ set nosplitbelow
|
|||
set nosplitright
|
||||
wincmd t
|
||||
set winheight=1 winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 105 + 102) / 205)
|
||||
exe 'vert 2resize ' . ((&columns * 99 + 102) / 205)
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
|
|
@ -49,15 +71,15 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 25 - ((24 * winheight(0) + 37) / 75)
|
||||
let s:l = 25 - ((17 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
25
|
||||
normal! 01l
|
||||
normal! 019l
|
||||
wincmd w
|
||||
argglobal
|
||||
edit includes/ft_ls.h
|
||||
edit src/main.c
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
|
|
@ -67,16 +89,16 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 24 - ((23 * winheight(0) + 37) / 75)
|
||||
let s:l = 19 - ((18 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
24
|
||||
normal! 0
|
||||
19
|
||||
normal! 01l
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 105 + 102) / 205)
|
||||
exe 'vert 2resize ' . ((&columns * 99 + 102) / 205)
|
||||
tabedit src/lib_parse.c
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
tabedit src/ft_dir_get_ents.c
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
|
|
@ -86,8 +108,8 @@ set nosplitbelow
|
|||
set nosplitright
|
||||
wincmd t
|
||||
set winheight=1 winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 105 + 102) / 205)
|
||||
exe 'vert 2resize ' . ((&columns * 99 + 102) / 205)
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
|
|
@ -98,15 +120,86 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 41 - ((32 * winheight(0) + 37) / 75)
|
||||
let s:l = 31 - ((30 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
41
|
||||
31
|
||||
normal! 054l
|
||||
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 = 30 - ((29 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
30
|
||||
normal! 01l
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
tabedit src/lib_ent.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 = 18 - ((17 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
18
|
||||
normal! 0
|
||||
tabedit libft/src/lst/ft_lstdel.c
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
1wincmd h
|
||||
wincmd w
|
||||
set nosplitbelow
|
||||
set nosplitright
|
||||
wincmd t
|
||||
set winheight=1 winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
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 = 19 - ((18 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
19
|
||||
normal! 0
|
||||
wincmd w
|
||||
argglobal
|
||||
edit src/lib_ls_long2.c
|
||||
edit libft/src/lst/ft_lst_delif.c
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
|
|
@ -116,16 +209,38 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 68 - ((37 * winheight(0) + 37) / 75)
|
||||
let s:l = 31 - ((30 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
68
|
||||
normal! 03l
|
||||
31
|
||||
normal! 0
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 105 + 102) / 205)
|
||||
exe 'vert 2resize ' . ((&columns * 99 + 102) / 205)
|
||||
tabnext 1
|
||||
exe 'vert 1resize ' . ((&columns * 104 + 104) / 209)
|
||||
exe 'vert 2resize ' . ((&columns * 104 + 104) / 209)
|
||||
tabedit src/ft_ent_get_dirs.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 = 35 - ((34 * winheight(0) + 40) / 80)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
35
|
||||
normal! 03l
|
||||
tabnext 4
|
||||
if exists('s:wipebuf')
|
||||
silent exe 'bwipe ' . s:wipebuf
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:10:03 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 16:20:29 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:09:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,11 +16,13 @@
|
|||
# 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 FT_MINORBITS 20
|
||||
# define FT_MINORMASK ((1U << FT_MINORBITS) - 1)
|
||||
# define FT_MINOR(dev) ((unsigned int) ((dev) >> FT_MINORBITS))
|
||||
# define FT_MAJOR(dev) ((unsigned int) ((dev) & FT_MINORMASK))
|
||||
# define FT_MKDEV(ma,mi) (((ma) << FT_MINORBITS) | (mi))
|
||||
|
||||
# define OPTS_LL 0x0001
|
||||
# define OPTS_LA 0x0002
|
||||
# define OPTS_LR 0x0004
|
||||
# define OPTS_UR 0x0008
|
||||
# define OPTS_LT 0x0010
|
||||
# define OPTS_HEAD 0x0020
|
||||
|
||||
# include "libft.h"
|
||||
# include <errno.h>
|
||||
|
|
@ -53,22 +55,24 @@ struct s_pads
|
|||
typedef struct s_lsdata t_lsdata;
|
||||
typedef struct s_pads t_pads;
|
||||
|
||||
char *ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent);
|
||||
int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent);
|
||||
|
||||
void ft_ls_dirs(t_list *dir, char *opts);
|
||||
void ft_ls_files(t_list *ent, t_list *dir, char *opts);
|
||||
void ft_ls_dirs(t_list *dir, int opts);
|
||||
void ft_ls_files(t_list *ent, t_list *dir, int opts);
|
||||
|
||||
void ft_lsdata_filename(t_lsdata *data);
|
||||
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_cmp0(t_lsdata *dat1, char *dataref);
|
||||
|
||||
void ft_ent_filter(t_list **ent, char *opts);
|
||||
void ft_ent_sort(t_list **ent, char *opts);
|
||||
void ft_ent_filter(t_list **ent, int opts);
|
||||
void ft_ent_sort(t_list **ent, int opts);
|
||||
void ft_ent_print(
|
||||
t_list *ent, char *opts, t_lsdata *topdir, t_list *nextdir);
|
||||
t_list *ent, int *opts, t_lsdata *topdir, t_list *nextdir);
|
||||
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_dir_get_ents(t_lsdata *topdir);
|
||||
|
||||
void ft_ls_short(t_list *ent);
|
||||
|
|
|
|||
2
ls/libft
2
ls/libft
|
|
@ -1 +1 @@
|
|||
Subproject commit 38bb3a862175ea55b1243c37d7afcabd7d46dc45
|
||||
Subproject commit 1550a6dd5dca7c20e27ace800a797f3181b69772
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 14:58:49 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 15:04:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:21:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,9 +25,10 @@ t_list *ft_dir_get_ents(t_lsdata *topdir)
|
|||
{
|
||||
data.path = ft_str3join(topdir->path, "/", dirent->d_name);
|
||||
lstat(data.path, &data.stat);
|
||||
data.dirent = ft_memalloc(sizeof(dirent));
|
||||
ft_memcpy(data.dirent, &dirent, sizeof(dirent));
|
||||
data.dirent = ft_memalloc(sizeof(*dirent) + 1);
|
||||
ft_memcpy(data.dirent, dirent, sizeof(*dirent));
|
||||
ft_lstadd(&ent, ft_lstnew(&data, sizeof(data)));
|
||||
ft_printf("malloc'd ent at %p (%s)\n", ent, data.path);
|
||||
}
|
||||
closedir(stream);
|
||||
return (ent);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/08 11:10:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 15:05:59 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 12:28:28 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ void ft_ent_free(void *ptr, size_t size)
|
|||
if (data->path)
|
||||
ft_strdel(&data->path);
|
||||
if (data->dirent)
|
||||
free(data->dirent);
|
||||
ft_memdel((void **)&data->dirent);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
ls/src/ft_ent_get_dirs.c
Normal file
39
ls/src/ft_ent_get_dirs.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ent_get_dirs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/16 15:46:27 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 18:18:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_ls.h"
|
||||
|
||||
t_list *ft_ent_get_dirs(t_list **ent)
|
||||
{
|
||||
t_lsdata *data;
|
||||
struct dirent *dirent;
|
||||
t_list *dir;
|
||||
t_list *lst;
|
||||
t_list *tmp;
|
||||
|
||||
dir = NULL;
|
||||
lst = *ent;
|
||||
while (lst)
|
||||
{
|
||||
tmp = lst;
|
||||
data = lst->content;
|
||||
dirent = data->dirent;
|
||||
lst = lst->next;
|
||||
if (dirent->d_type == DT_DIR
|
||||
&& ft_strcmp(ft_path_notdir(data->path), ".")
|
||||
&& ft_strcmp(ft_path_notdir(data->path), ".."))
|
||||
{
|
||||
ft_lsteadd(&dir, ft_lst_removeif(ent, tmp->content, &ft_addrcmp));
|
||||
}
|
||||
}
|
||||
return (dir);
|
||||
}
|
||||
33
ls/src/ft_ent_has_dir.c
Normal file
33
ls/src/ft_ent_has_dir.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ent_has_dir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/16 15:42:54 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 15:45:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_ls.h"
|
||||
|
||||
int ft_ent_has_dir(t_list *ent)
|
||||
{
|
||||
t_lsdata *data;
|
||||
struct dirent *dirent;
|
||||
|
||||
while (ent)
|
||||
{
|
||||
data = ent->content;
|
||||
dirent = data->dirent;
|
||||
if (dirent->d_type == DT_DIR
|
||||
&& ft_strcmp(ft_path_notdir(data->path), ".")
|
||||
&& ft_strcmp(ft_path_notdir(data->path), ".."))
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
ent = ent->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 14:57:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 15:04:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:22:06 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_ls.h"
|
||||
|
||||
void ft_ls_dirs(t_list *dir, char *opts)
|
||||
void ft_ls_dirs(t_list *dir, int opts)
|
||||
{
|
||||
t_list *dir_r;
|
||||
t_list *ent;
|
||||
|
|
@ -20,31 +20,34 @@ void ft_ls_dirs(t_list *dir, char *opts)
|
|||
t_list *tmp;
|
||||
|
||||
ft_ent_sort(&dir, opts);
|
||||
ent = NULL;
|
||||
while (dir)
|
||||
{
|
||||
dirdata = dir->content;
|
||||
tmp = dir;
|
||||
dir = dir->next;
|
||||
ft_lstdel(&ent, &ft_ent_free);
|
||||
ent = ft_dir_get_ents(dirdata);
|
||||
ft_ent_sort(&ent, opts);
|
||||
ft_ent_filter(&ent, opts);
|
||||
ft_ent_print(ent, opts, dirdata, dir);
|
||||
if (ft_strchr(opts, 'R'))
|
||||
ft_ent_print(ent, &opts, dirdata, dir);
|
||||
if (opts & OPTS_UR)
|
||||
{
|
||||
dir_r = ft_ent_get_dirs(ent);
|
||||
dir_r = ft_ent_get_dirs(&ent);
|
||||
ft_lst_merge(&dir_r, dir);
|
||||
dir = dir_r;
|
||||
}
|
||||
ft_lstdelone(&tmp, &ft_ent_free);
|
||||
}
|
||||
ft_lstdel(&ent, &ft_ent_free);
|
||||
}
|
||||
|
||||
void ft_ls_files(t_list *ent, t_list *dir, char *opts)
|
||||
void ft_ls_files(t_list *ent, t_list *dir, int opts)
|
||||
{
|
||||
if (ent)
|
||||
{
|
||||
ft_ent_sort(&ent, opts);
|
||||
ft_ent_filter(&ent, opts);
|
||||
ft_ent_print(ent, opts, NULL, dir);
|
||||
ft_ent_print(ent, &opts, NULL, dir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,74 +6,47 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:00:05 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 15:01:55 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:22:22 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_ls.h"
|
||||
|
||||
void ft_ent_filter(t_list **ent, char *opts)
|
||||
void ft_ent_filter(t_list **ent, int opts)
|
||||
{
|
||||
if (!ft_strchr(opts, 'a'))
|
||||
if (!(opts & OPTS_LA))
|
||||
ft_lst_delif(ent, ".", &ft_lsdata_cmp0, &ft_ent_free);
|
||||
}
|
||||
|
||||
void ft_ent_sort(t_list **ent, char *opts)
|
||||
void ft_ent_sort(t_list **ent, int opts)
|
||||
{
|
||||
int (*ft_sort)();
|
||||
|
||||
if (ft_strchr(opts, 't'))
|
||||
if (opts & OPTS_LT)
|
||||
ft_sort = &ft_lsdata_cmp_time;
|
||||
else
|
||||
ft_sort = &ft_lsdata_cmp_name;
|
||||
ft_lst_sort(ent, ft_sort);
|
||||
if (ft_strchr(opts, 'r'))
|
||||
if (opts & OPTS_LR)
|
||||
ft_lst_reverse(ent);
|
||||
}
|
||||
|
||||
void ft_ent_print(t_list *ent, char *opts, t_lsdata *topdir, t_list *nextdir)
|
||||
void ft_ent_print(t_list *ent, int *opts, t_lsdata *topdir, t_list *nextdir)
|
||||
{
|
||||
char *opt;
|
||||
|
||||
if (!(opt = ft_strchr(opts, '0')))
|
||||
if (*opts & OPTS_HEAD)
|
||||
{
|
||||
if (topdir)
|
||||
ft_printf("%s:\n", topdir->path);
|
||||
}
|
||||
else
|
||||
*opt = '.';
|
||||
*opts |= OPTS_HEAD;
|
||||
if (ent)
|
||||
{
|
||||
if (ft_strchr(opts, 'l'))
|
||||
if (*opts & OPTS_LL)
|
||||
ft_ls_long(ent, topdir);
|
||||
else
|
||||
ft_ls_short(ent);
|
||||
}
|
||||
if (nextdir)
|
||||
ft_putendl("");
|
||||
}
|
||||
|
||||
t_list *ft_ent_get_dirs(t_list *ent)
|
||||
{
|
||||
t_lsdata *data;
|
||||
struct dirent *dirent;
|
||||
t_list *dir;
|
||||
t_list *tmp;
|
||||
|
||||
dir = NULL;
|
||||
while (ent)
|
||||
{
|
||||
data = ent->content;
|
||||
dirent = data->dirent;
|
||||
tmp = ent;
|
||||
ent = ent->next;
|
||||
if (dirent->d_type == DT_DIR
|
||||
&& ft_strcmp(dirent->d_name, ".")
|
||||
&& ft_strcmp(dirent->d_name, ".."))
|
||||
{
|
||||
tmp->next = NULL;
|
||||
ft_lsteadd(&dir, tmp);
|
||||
}
|
||||
}
|
||||
return (dir);
|
||||
if (nextdir || ((*opts & OPTS_UR) && ft_ent_has_dir(ent)))
|
||||
ft_putchar('\n');
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 14:57:43 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 15:29:02 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 11:05:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
void ft_error_option(char c)
|
||||
{
|
||||
ft_printf(LS_MSG_ILLEGAL_OPT, c);
|
||||
ft_printf(LS_MSG_USAGE, LS_LEGAL_OPTS);
|
||||
ft_dprintf(2, LS_MSG_ILLEGAL_OPT, c);
|
||||
ft_dprintf(2, LS_MSG_USAGE, LS_LEGAL_OPTS);
|
||||
}
|
||||
|
||||
void ft_error_dir(char *s)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 14:59:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 10:54:39 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:59:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -47,6 +47,9 @@ void ft_ls_long_date(struct stat *stat)
|
|||
? ft_strsub(date, 11, 5)
|
||||
: ft_strsub(date, 20, 4);
|
||||
ft_printf(" %s %s %5s", month, day, time);
|
||||
free(month);
|
||||
free(day);
|
||||
free(time);
|
||||
}
|
||||
|
||||
void ft_ls_long_type(mode_t m)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:01:01 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 16:26:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:51:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,28 +14,15 @@
|
|||
|
||||
void ft_ls_long_rights(mode_t m)
|
||||
{
|
||||
int i;
|
||||
char *rights;
|
||||
|
||||
i = 0;
|
||||
rights = ft_itoa_base(m, "01", "");
|
||||
rights = rights + ft_strlen(rights) - 9;
|
||||
while (rights[i])
|
||||
{
|
||||
if (rights[i] == '0')
|
||||
rights[i] = '-';
|
||||
else
|
||||
{
|
||||
if (i % 3 == 0)
|
||||
rights[i] = 'r';
|
||||
else if (i % 3 == 1)
|
||||
rights[i] = 'w';
|
||||
else if (i % 3 == 2)
|
||||
rights[i] = 'x';
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ft_printf("%s", rights);
|
||||
ft_putchar(m & S_IRUSR ? 'r' : '-');
|
||||
ft_putchar(m & S_IWUSR ? 'w' : '-');
|
||||
ft_putchar(m & S_IXUSR ? 'x' : '-');
|
||||
ft_putchar(m & S_IRGRP ? 'r' : '-');
|
||||
ft_putchar(m & S_IWGRP ? 'w' : '-');
|
||||
ft_putchar(m & S_IXGRP ? 'x' : '-');
|
||||
ft_putchar(m & S_IROTH ? 'r' : '-');
|
||||
ft_putchar(m & S_IWOTH ? 'w' : '-');
|
||||
ft_putchar(m & S_IXOTH ? 'x' : '-');
|
||||
}
|
||||
|
||||
int ft_ls_long_lnk(t_lsdata *data)
|
||||
|
|
@ -66,8 +53,6 @@ int ft_ls_long_xattr(mode_t m, char *path)
|
|||
if ((n = ft_xattr_count(path)) == -1)
|
||||
{
|
||||
;
|
||||
/* ft_printf("\ncouldnt get xattr: %i\n", n); */
|
||||
/* return (1); */
|
||||
}
|
||||
if (n > 0)
|
||||
x = '@';
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:02:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 16:26:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:46:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,50 +36,61 @@ static void ft_ls_parse_files(int ac, char **av, t_list **dir, t_list **ent)
|
|||
}
|
||||
}
|
||||
|
||||
static int ft_ls_parse_options(int ac, char **av, char *opts)
|
||||
static int ft_getopts(char *str)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int i;
|
||||
int opts;
|
||||
|
||||
i = 0;
|
||||
opts = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == 'l')
|
||||
opts |= OPTS_LL;
|
||||
else if (str[i] == 'a')
|
||||
opts |= OPTS_LA;
|
||||
else if (str[i] == 't')
|
||||
opts |= OPTS_LT;
|
||||
else if (str[i] == 'r')
|
||||
opts |= OPTS_LR;
|
||||
else if (str[i] == 'R')
|
||||
opts |= OPTS_UR;
|
||||
else
|
||||
{
|
||||
ft_error_option(str[i]);
|
||||
exit(1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (opts);
|
||||
}
|
||||
|
||||
static int ft_ls_parse_options(int ac, char **av, int *opts)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (++i < ac)
|
||||
{
|
||||
if (av[i][0] == '-')
|
||||
{
|
||||
j = 0;
|
||||
while (av[i][++j])
|
||||
{
|
||||
if (!ft_strchr(LS_LEGAL_OPTS, av[i][j]))
|
||||
{
|
||||
ft_error_option(av[i][j]);
|
||||
exit(1);
|
||||
}
|
||||
else if (!ft_strchr(opts, av[i][j]))
|
||||
ft_strcat(opts, av[i] + j);
|
||||
}
|
||||
}
|
||||
*opts |= ft_getopts(av[i] + 1);
|
||||
else
|
||||
break ;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent)
|
||||
int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent)
|
||||
{
|
||||
int i;
|
||||
char *opts;
|
||||
t_lsdata data;
|
||||
int i;
|
||||
int opts;
|
||||
|
||||
if (!(opts = (char *)ft_strnew(sizeof(char) * 7)))
|
||||
return (NULL);
|
||||
i = ft_ls_parse_options(ac, av, opts);
|
||||
ft_strcat(opts, (ac - i <= 1) ? "0" : "");
|
||||
opts = 0;
|
||||
i = ft_ls_parse_options(ac, av, &opts);
|
||||
opts &= ((ac - i <= 1) ? ~0 : ~OPTS_HEAD);
|
||||
if (i == ac)
|
||||
{
|
||||
data.path = ft_strdup(".");
|
||||
data.dirent = NULL;
|
||||
ft_lstadd(dir, ft_lstnew(&data, sizeof(data)));
|
||||
}
|
||||
ft_ls_parse_files(ac - i, av + i, dir, ent);
|
||||
ft_ls_parse_files(1, (char*[2]){"."}, dir, ent);
|
||||
else
|
||||
ft_ls_parse_files(ac - i, av + i, dir, ent);
|
||||
return (opts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:00:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/08 16:26:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:08:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_list *dir;
|
||||
t_list *ent;
|
||||
char *opts;
|
||||
t_list *dir;
|
||||
t_list *ent;
|
||||
int opts;
|
||||
|
||||
dir = NULL;
|
||||
ent = NULL;
|
||||
|
|
@ -24,6 +24,5 @@ int main(int ac, char **av)
|
|||
ft_ls_files(ent, dir, opts);
|
||||
ft_lstdel(&ent, &ft_ent_free);
|
||||
ft_ls_dirs(dir, opts);
|
||||
ft_strdel(&opts);
|
||||
return (errno);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue