diff --git a/ls/.gitmodules b/ls/.gitmodules index c82793fb..e69de29b 100644 --- a/ls/.gitmodules +++ b/ls/.gitmodules @@ -1,3 +0,0 @@ -[submodule "libft"] - path = libft - url = https://github.com/jzck/libft diff --git a/ls/.tags b/ls/.tags index cd9fc8b8..730a5fa9 100644 --- a/ls/.tags +++ b/ls/.tags @@ -29,12 +29,12 @@ 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, i/ +ft_ls_parse_files src/lib_parse.c /^static void ft_ls_parse_files(char **av, int opts,/ ft_ls_parse_options src/lib_parse.c /^static int ft_ls_parse_options(int ac, char **av, / ft_ls_postname src/ft_ls_postname.c /^void ft_ls_postname(mode_t m, int opts)$/ 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_size src/lib_lsdata.c /^int ft_lsdata_cmp_size(t_lsdata *dat1, t_lsdata */ +ft_lsdata_cmpa src/lib_lsdata.c /^int ft_lsdata_cmpa(t_lsdata *data, char *dataref)/ ft_lsdata_filename src/lib_lsdata.c /^void ft_lsdata_filename(t_lsdata *data, t_lsdata */ diff --git a/ls/Makefile b/ls/Makefile index a4bf35a7..cf297110 100644 --- a/ls/Makefile +++ b/ls/Makefile @@ -1,9 +1,9 @@ NAME = ft_ls CC = gcc -TAGFILE = .tags D_SRC = src F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$") +F_SRC := ft_dir_get_ents.c ft_ent_free.c ft_ent_get_dirs.c ft_ent_has_dir.c ft_ls.c ft_ls_color.c ft_ls_long.c ft_ls_postname.c ft_ls_short.c lib_ent.c lib_error.c lib_ls_long.c lib_ls_long2.c lib_lsdata.c lib_parse.c lib_time.c main.c DF_SRC := $(addprefix $(D_SRC)/, $(F_SRC)) D_OBJ = obj @@ -14,18 +14,14 @@ D_INC = includes libft/includes O_INC = $(addprefix -I, $(D_INC)) W_FLAGS = -Wall -Wextra -Werror -D_FLAGS = -g +D_FLAGS = MKDIR = mkdir -p RM = /bin/rm -rf -.PHONY: all clean fclean re tags test libft +.PHONY: all clean fclean re -all: $(NAME) $(TAGFILE) - -$(TAGFILE): $(D_SRC)/*.c - @ctags -f $(TAGFILE) $(addprefix $(D_SRC)/, $(F_SRC)) - @echo "Making tags..." +all: $(NAME) $(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC) @$(MKDIR) $(D_OBJ) @@ -35,15 +31,13 @@ $(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC) libft: @$(MAKE) -C libft/ 2>/dev/null -$(NAME): libft $(DF_OBJ) libft/libft.a +$(NAME): $(DF_OBJ) libft $(CC) $(O_INC) -Llibft -lft $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS) clean: $(RM) $(D_OBJ) - @$(MAKE) -C libft clean 2>/dev/null fclean: clean $(RM) $(NAME) - @$(MAKE) -C libft fclean 2>/dev/null re: fclean all diff --git a/ls/Session.vim b/ls/Session.vim deleted file mode 100644 index fec1c30d..00000000 --- a/ls/Session.vim +++ /dev/null @@ -1,90 +0,0 @@ -let SessionLoad = 1 -if &cp | set nocp | endif -let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0 -let v:this_session=expand(":p") -silent only -cd ~/ -if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' - let s:wipebuf = bufnr('%') -endif -set shortmess=aoO -badd +1 src/lib_ls_long2.c -badd +27 src/ft_ls_long.c -badd +25 includes/ft_ls.h -badd +60 ~/.tmux.conf -badd +52 src/lib_ls_long.c -badd +35 src/lib_lsdata.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 +14 src/lib_dirents.c -badd +21 src/main.c -badd +30 src/ft_ls.c -badd +21 src/ft_ent_free.c -badd +1 Makefile -badd +16 src/lib_error.c -badd +32 src/lib_dirs.c -badd +31 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 +1 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 +1 libft/src/mem/ft_memcpy.c -badd +19 libft/src/mem/ft_memdel.c -badd +31 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 +35 src/ft_ent_get_dirs.c -badd +19 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 -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 = 1 - ((0 * winheight(0) + 40) / 81) -if s:l < 1 | let s:l = 1 | endif -exe s:l -normal! zt -1 -normal! 0 -tabnext 1 -if exists('s:wipebuf') - silent exe 'bwipe ' . s:wipebuf -endif -unlet! s:wipebuf -set winheight=1 winwidth=20 shortmess=filnxtToO -let s:sx = expand(":p:r")."x.vim" -if file_readable(s:sx) - exe "source " . fnameescape(s:sx) -endif -let &so = s:so_save | let &siso = s:siso_save -let g:this_session = v:this_session -let g:this_obsession = v:this_session -let g:this_obsession_status = 2 -doautoall SessionLoadPost -unlet SessionLoad -" vim: set ft=vim : diff --git a/ls/includes/ft_ls.h b/ls/includes/ft_ls.h index 7f96e92b..ef4475af 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/25 18:26:44 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 13:09:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/ls/libft b/ls/libft deleted file mode 160000 index a08d8287..00000000 --- a/ls/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a08d8287e8e798ca7e18f9c4de9fbfa98aa395aa diff --git a/ls/src/ft_ls_color.c b/ls/src/ft_ls_color.c index afb60a68..427b8d77 100644 --- a/ls/src/ft_ls_color.c +++ b/ls/src/ft_ls_color.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/25 13:39:11 by jhalford #+# #+# */ -/* Updated: 2016/11/25 16:00:01 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 11:57:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,31 +14,24 @@ void ft_ls_color(mode_t m) { - char fg[20]; - char bg[20]; + t_color color; - ft_strcpy(fg, FG_DEFAULT); - ft_strcpy(bg, BG_DEFAULT); - ft_strcpy(fg, S_ISDIR(m) ? FG_BLUE : fg); - ft_strcpy(fg, S_ISLNK(m) ? FG_MAGENTA : fg); - ft_strcpy(fg, S_ISSOCK(m) ? FG_GREEN : fg); - ft_strcpy(fg, S_ISFIFO(m) ? FG_YELLOW : fg); - ft_strcpy(fg, S_ISREG(m) && (S_IXUGO & m) ? FG_RED : fg); - ft_strcpy(fg, S_ISBLK(m) ? FG_BLUE : fg); - ft_strcpy(bg, S_ISBLK(m) ? BG_CYAN : bg); - ft_strcpy(fg, S_ISCHR(m) ? FG_BLUE : fg); - ft_strcpy(bg, S_ISCHR(m) ? BG_YELLOW : bg); - ft_strcpy(fg, S_ISREG(m) && (S_IXUGO & m) && - (S_ISGID & m) ? FG_BLACK : fg); - ft_strcpy(bg, S_ISREG(m) && (S_IXUGO & m) && - (S_ISGID & m) ? BG_CYAN : bg); - ft_strcpy(fg, S_ISREG(m) && (S_IXUGO & m) && - (S_ISUID & m) ? FG_BLACK : fg); - ft_strcpy(bg, S_ISREG(m) && (S_IXUGO & m) && - (S_ISUID & m) ? BG_RED : bg); - ft_strcpy(fg, S_ISDIR(m) && (S_IWOTH & m) && (S_ISVTX & m) ? FG_BLACK : fg); - ft_strcpy(bg, S_ISDIR(m) && (S_IWOTH & m) && (S_ISVTX & m) ? BG_GREEN : bg); - ft_strcpy(fg, S_ISDIR(m) && (S_IWOTH & m) && !(S_ISVTX & m) ? FG_BLACK : fg); - ft_strcpy(bg, S_ISDIR(m) && (S_IWOTH & m) && !(S_ISVTX & m) ? BG_YELLOW : bg); - ft_color_set(fg, bg); + ft_color_mk(&color, FG_DEFAULT, BG_DEFAULT); + ft_color_mkif(&color, S_ISDIR(m), FG_BLUE, BG_DEFAULT); + ft_color_mkif(&color, S_ISLNK(m), FG_MAGENTA, BG_DEFAULT); + ft_color_mkif(&color, S_ISLNK(m), FG_MAGENTA, BG_DEFAULT); + ft_color_mkif(&color, S_ISSOCK(m), FG_GREEN, BG_DEFAULT); + ft_color_mkif(&color, S_ISFIFO(m), FG_YELLOW, BG_DEFAULT); + ft_color_mkif(&color, S_ISREG(m) && (S_IXUGO & m), FG_RED, BG_DEFAULT); + ft_color_mkif(&color, S_ISBLK(m), FG_BLUE, BG_CYAN); + ft_color_mkif(&color, S_ISCHR(m), FG_BLUE, BG_YELLOW); + ft_color_mkif(&color, S_ISREG(m) && (S_IXUGO & m) && (S_ISGID & m), + FG_BLACK, BG_CYAN); + ft_color_mkif(&color, S_ISREG(m) && (S_IXUGO & m) && (S_ISUID & m), + FG_BLACK, BG_RED); + ft_color_mkif(&color, S_ISDIR(m) && (S_IWOTH & m) && (S_ISVTX & m), + FG_BLACK, BG_GREEN); + ft_color_mkif(&color, S_ISDIR(m) && (S_IWOTH & m) && !(S_ISVTX & m), + FG_BLACK, BG_YELLOW); + ft_color_set(color); } diff --git a/ls/src/lib_error.c b/ls/src/lib_error.c index a5dd8224..f26c3ed9 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/25 13:08:52 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 11:57:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,18 +22,15 @@ void ft_error_access(char *s) { ft_dprintf(2, "ls: "); perror(ft_path_notdir(s)); - /* ft_dprintf(2, LS_MSG_ACC_ERR, ft_path_notdir(s)); */ } void ft_error_dir(char *s) { ft_dprintf(2, "ls: "); if (*s) - /* ft_dprintf(2, LS_MSG_FILE_ERR, s); */ perror(s); else { - /* ft_dprintf(2, LS_MSG_FILE_ERR, "fts_open"); */ perror("fts_open"); exit(1); } diff --git a/ls/src/lib_ls_long.c b/ls/src/lib_ls_long.c index 9276903a..0d10bcf3 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/25 18:31:12 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 11:57:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,7 +55,8 @@ void ft_ls_long_date(struct stat *stat, int opts) ft_printf(" %s %s %s:%s:%s %s", time->month, time->day, time->hour, time->min, time->sec, time->year); else if (ft_time_isrecent(st_time)) - ft_printf(" %s %s %s:%s", time->month, time->day, time->hour, time->min); + ft_printf(" %s %s %s:%s", + time->month, time->day, time->hour, time->min); else ft_printf(" %s %s %s", time->month, time->day, time->year); ft_mytime_free(&time); diff --git a/ls/src/lib_ls_long2.c b/ls/src/lib_ls_long2.c index a8acf809..0432fff1 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/25 17:22:53 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 13:08:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,15 +55,15 @@ int ft_ls_long_xattr(mode_t m, char *path) { char x; acl_t acl; - acl_entry_t acl_entry; - acl = acl_get_file(path, ACL_TYPE_DEFAULT | ACL_TYPE_ACCESS); - if ((acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry)) == 0) + x = ' '; + if (!S_ISBLK(m) && !S_ISCHR(m) && ft_xattr_count(path) > 0) + x = '@'; + else if ((acl = acl_get_file(path, ACL_TYPE_EXTENDED))) + { x = '+'; - else if (!S_ISBLK(m) && !S_ISCHR(m)) - x = ft_xattr_count(path) > 0 ? '@' : ' '; - else - x = ' '; + acl_free((void*)acl); + } ft_putchar(x); return (0); } @@ -107,10 +107,9 @@ int ft_ls_long_pads(t_list *ent, t_pads *pads) FT_MAX_WR(pads->nlink, (int)ft_uilen(stat.st_nlink)); FT_MAX_WR(pads->size, (int)ft_ilen(stat.st_size)); if (S_ISCHR(stat.st_mode) || S_ISBLK(stat.st_mode)) - { FT_MAX_WR(pads->minor, (int)ft_ilen(minor(stat.st_rdev))); + if (S_ISCHR(stat.st_mode) || S_ISBLK(stat.st_mode)) FT_MAX_WR(pads->major, (int)ft_ilen(major(stat.st_rdev))); - } } pads->size = FT_MAX(pads->size, pads->minor ? pads->minor + pads->major + 3 : pads->size); diff --git a/ls/src/lib_lsdata.c b/ls/src/lib_lsdata.c index a492b197..d33763ab 100644 --- a/ls/src/lib_lsdata.c +++ b/ls/src/lib_lsdata.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 14:59:09 by jhalford #+# #+# */ -/* Updated: 2016/11/25 18:26:53 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 11:15:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,13 +17,13 @@ void ft_lsdata_filename(t_lsdata *data, t_lsdata *topdir, int opts) struct dirent *dirent; dirent = data->dirent; - if (opts & OPTS_UG) + if (opts & OPTS_UG && isatty(1)) ft_ls_color(data->stat.st_mode); if (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); - if (opts & OPTS_UG) + if (opts & OPTS_UG && isatty(1)) ft_color_reset(); ft_ls_postname(data->stat.st_mode, opts); } diff --git a/ls/src/lib_parse.c b/ls/src/lib_parse.c index a73ce32f..6d54a36f 100644 --- a/ls/src/lib_parse.c +++ b/ls/src/lib_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:02:46 by jhalford #+# #+# */ -/* Updated: 2016/11/25 18:31:15 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 12:49:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ t_opts g_opts[] = {'T', OPTS_UT, 0}, {'U', OPTS_UU, TIME_MASK}, {'a', OPTS_LA, 0}, - {'c', OPTS_LC, 0}, + {'c', OPTS_LC, TIME_MASK}, {'d', OPTS_LD, 0}, {'f', OPTS_LF, 0}, {'g', OPTS_LG, 0}, @@ -36,15 +36,14 @@ t_opts g_opts[] = {0, 0, 0}, }; - -static void ft_ls_parse_files(int ac, char **av, int opts, t_list **dir, t_list **ent) +static void ft_ls_parse_files(char **av, int opts, t_list **dir, t_list **ent) { t_lsdata data; int i; data.dirent = NULL; i = -1; - while (++i < ac) + while (av[++i]) { if (stat(av[i], &data.stat) < 0) if (lstat(av[i], &data.stat) < 0) @@ -128,8 +127,8 @@ int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent) opts |= (ac - i > 1) ? OPTS_HEAD : 0; ft_sstrsort(av + i, &ft_strcmp); if (i == ac) - ft_ls_parse_files(1, (char*[2]){"."}, opts,dir, ent); + ft_ls_parse_files((char *[2]){"."}, opts, dir, ent); else - ft_ls_parse_files(ac - i, av + i, opts, dir, ent); + ft_ls_parse_files(av + i, opts, dir, ent); return (opts); } diff --git a/ls/src/main.c b/ls/src/main.c index b244c858..c3508820 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/25 10:49:54 by jhalford ### ########.fr */ +/* Updated: 2016/11/27 12:06:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */