norm , acl and thats it (color done)

This commit is contained in:
Jack Halford 2016-11-25 18:34:58 +01:00
parent d7c7816207
commit d931c172d1
15 changed files with 217 additions and 143 deletions

View file

@ -15,6 +15,7 @@ ft_error_access src/lib_error.c /^void ft_error_access(char *s)$/
ft_error_dir src/lib_error.c /^void ft_error_dir(char *s)$/
ft_error_option src/lib_error.c /^void ft_error_option(char c)$/
ft_getopts src/lib_parse.c /^static int ft_getopts(char *str)$/
ft_ls_color src/ft_ls_color.c /^void ft_ls_color(mode_t m)$/
ft_ls_dirs src/ft_ls.c /^void ft_ls_dirs(t_list *dir, int opts)$/
ft_ls_files src/ft_ls.c /^void ft_ls_files(t_list **ent, t_list **dir, t_lsd/
ft_ls_long src/ft_ls_long.c /^int ft_ls_long(t_list *ent, t_lsdata *topdir, int/
@ -30,6 +31,7 @@ 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_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)/

View file

@ -8,7 +8,7 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
badd +98 src/lib_ls_long2.c
badd +1 src/lib_ls_long2.c
badd +27 src/ft_ls_long.c
badd +25 includes/ft_ls.h
badd +60 ~/.tmux.conf
@ -48,9 +48,7 @@ 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
argglobal
silent! argdel *
argadd src/lib_ls_long2.c
args src/lib_ls_long2.c
edit src/main.c
set splitbelow splitright
set nosplitbelow
@ -67,7 +65,7 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 20) / 41)
let s:l = 1 - ((0 * winheight(0) + 40) / 81)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt

View file

@ -6,48 +6,57 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:10:03 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:40:59 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:26:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LS_H
# define FT_LS_H
# define LS_LEGAL_OPTS "larRt"
# define LS_LEGAL_OPTS "AFGRUSTacdfgloprtu1"
# define LS_MSG_ILLEGAL_OPT "ft_ls: illegal option -- %c\n"
# define LS_MSG_USAGE "usage: ls [-%s] [file ...]\n"
# define LS_MSG_FILE_ERR "ls: %s: No such file or directory\n"
# define LS_MSG_ACC_ERR "ls: %s: Permission denied\n"
# define OPTS_LA 0x0000001
# define OPTS_LC 0x0000002
# define OPTS_LD 0x0000004
# define OPTS_LF 0x0000008
# define OPTS_LL 0x0000010
# define OPTS_LP 0x0000020
# define OPTS_LR 0x0000040
# define OPTS_LT 0x0000080
# define OPTS_LU 0x0000100
# define OPTS_UA 0x0000200
# define OPTS_UR 0x0000400
# define OPTS_UU 0x0000800
# define OPTS_US 0x0001000
# define OPTS_ONE 0x0002000
# define OPTS_ERR_A 0x0010000
# define OPTS_HEAD 0x0100000
# ifndef S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
# endif
# define TIME_MASK OPTS_LC | OPTS_LU | OPTS_UU
# define OPTS_LA 0x00000001
# define OPTS_LC 0x00000002
# define OPTS_LD 0x00000004
# define OPTS_LF 0x00000008
# define OPTS_LG 0x00000010
# define OPTS_LL 0x00000020
# define OPTS_LO 0x00000040
# define OPTS_LP 0x00000080
# define OPTS_LR 0x00000100
# define OPTS_LT 0x00000200
# define OPTS_LU 0x00000400
# define OPTS_UA 0x00000800
# define OPTS_UF 0x00001000
# define OPTS_UG 0x00002000
# define OPTS_UR 0x00004000
# define OPTS_UU 0x00008000
# define OPTS_US 0x00010000
# define OPTS_UT 0x00020000
# define OPTS_ONE 0x00040000
# define OPTS_ERR_A 0x00100000
# define OPTS_HEAD 0x01000000
# define TIME_MASK (OPTS_LC | OPTS_LU | OPTS_UU)
# include "libft.h"
# include <errno.h>
# include <stdio.h>
# include <dirent.h>
# include <unistd.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <time.h>
# include <pwd.h>
# include <grp.h>
# include <sys/xattr.h>
# include <sys/acl.h>
struct s_lsdata
{
@ -66,8 +75,18 @@ struct s_pads
int minor;
};
struct s_opts
{
char id;
int on;
int off;
};
typedef struct s_lsdata t_lsdata;
typedef struct s_pads t_pads;
typedef struct s_opts t_opts;
extern t_opts g_opts[];
int ft_ls_parse(int ac, char **av, t_list **dir, t_list **ent);
@ -79,11 +98,12 @@ 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_ls_postname(mode_t m, int opts);
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_size(t_lsdata *dat1, t_lsdata *dat2);
int ft_lsdata_cmp0(t_lsdata *dat1, char *dataref);
int ft_lsdata_cmpA(t_lsdata *data, char *dataref);
int ft_lsdata_cmpa(t_lsdata *data, char *dataref);
void ft_ent_filter(t_list **ent, int opts);
void ft_ent_sort(t_list **ent, int opts);
@ -91,8 +111,8 @@ void ft_ent_print(
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);
void ft_ent_free(void *ptr, size_t size);
t_list *ft_ent_get_dirs(t_list **ent);
t_list *ft_dir_get_ents(t_lsdata *topdir, int *opts);
void ft_ls_short(t_list *ent, t_lsdata *topdir, int opts);
@ -105,7 +125,7 @@ int ft_ls_long_pads(t_list *ent, t_pads *pads);
void ft_ls_long_type(mode_t m);
void ft_ls_long_rights(mode_t m);
int ft_ls_long_xattr(mode_t m, char *path);
int ft_ls_long_middle(struct stat *stat, t_pads *pads);
int ft_ls_long_middle(struct stat *stat, t_pads *pads, int opts);
void ft_ls_long_date(struct stat *stat, int opts);
int ft_ls_long_lnk(t_lsdata *data);
@ -113,5 +133,5 @@ void ft_error_option(char c);
void ft_error_dir(char *s);
void ft_error_access(char *s);
void ft_ent_free(void *ptr, size_t size);
void ft_ls_color(mode_t m);
#endif

@ -1 +1 @@
Subproject commit f7ed005fb174d79af6508d2bdd6eed7dbe99e483
Subproject commit 1f3da9014798ae1a2bc72a90c17bb9a03e327206

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 14:57:21 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:53:01 by jhalford ### ########.fr */
/* Updated: 2016/11/25 12:15:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,7 @@ void ft_ls_dirs(t_list *dir, int opts)
ent = ft_dir_get_ents(dirdata, &opts);
ft_ls_files(&ent, &dir, dirdata, &opts);
ft_lstdelone(&tmp, &ft_ent_free);
if (opts & OPTS_UR)
if (opts & OPTS_UR && !(opts & OPTS_LD))
{
dir_r = ft_ent_get_dirs(&ent);
ft_lst_merge(&dir_r, dir);

44
ls/src/ft_ls_color.c Normal file
View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ls_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 13:39:11 by jhalford #+# #+# */
/* Updated: 2016/11/25 16:00:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void ft_ls_color(mode_t m)
{
char fg[20];
char bg[20];
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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 14:58:05 by jhalford #+# #+# */
/* Updated: 2016/11/23 17:39:50 by jhalford ### ########.fr */
/* Updated: 2016/11/25 14:18:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,7 +43,7 @@ int ft_ls_long_print(t_list *ent, t_lsdata *topdir, t_pads pads, int opts)
ft_ls_long_rights(stat.st_mode);
if (ft_ls_long_xattr(stat.st_mode, data->path))
return (1);
if (ft_ls_long_middle(&stat, &pads))
if (ft_ls_long_middle(&stat, &pads, opts))
return (1);
ft_ls_long_date(&stat, opts);
ft_printf(" ");

33
ls/src/ft_ls_postname.c Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ls_postname.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 14:19:17 by jhalford #+# #+# */
/* Updated: 2016/11/25 15:59:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void ft_ls_postname(mode_t m, int opts)
{
char c;
c = 0;
if (opts & OPTS_UF)
{
c = S_ISDIR(m) ? '/' : c;
c = S_ISREG(m) && (S_IXUGO & m) ? '*' : c;
c = S_ISLNK(m) ? '@' : c;
c = S_ISSOCK(m) ? '=' : c;
c = S_ISWHT(m) ? '%' : c;
c = S_ISFIFO(m) ? '|' : c;
}
else if (opts & OPTS_LP && S_ISDIR(m))
c = '/';
if (c)
ft_putchar(c);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:00:05 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:54:38 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:27:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,12 +14,12 @@
void ft_ent_filter(t_list **ent, int opts)
{
if (!(opts & OPTS_LA))
if (!(opts & (OPTS_LA | OPTS_LF)))
{
if (!(opts & OPTS_UA))
ft_lst_delif(ent, ".", &ft_lsdata_cmp0, &ft_ent_free);
else
ft_lst_delif(ent, ".", &ft_lsdata_cmpA, &ft_ent_free);
ft_lst_delif(ent, ".", &ft_lsdata_cmpa, &ft_ent_free);
}
}
@ -60,7 +60,7 @@ void ft_ent_print(t_list *ent, int *opts, t_lsdata *topdir, t_list *nextdir)
}
if (ent)
{
if (*opts & OPTS_LL)
if (*opts & (OPTS_LL | OPTS_LG | OPTS_LO))
ft_ls_long(ent, topdir, *opts);
else
ft_ls_short(ent, topdir, *opts);
@ -72,7 +72,7 @@ void ft_ent_print(t_list *ent, int *opts, t_lsdata *topdir, t_list *nextdir)
}
if ((!topdir && nextdir && ent)
|| (topdir && nextdir)
|| (((*opts & OPTS_UR)
|| (((*opts & OPTS_UR) && !(*opts & OPTS_LD)
&& ent && ft_ent_has_dir(ent))))
ft_putchar('\n');
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 14:57:43 by jhalford #+# #+# */
/* Updated: 2016/11/23 14:04:08 by jhalford ### ########.fr */
/* Updated: 2016/11/25 13:08:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,21 +20,20 @@ void ft_error_option(char c)
void ft_error_access(char *s)
{
/* ft_dprintf(2, LS_MSG_ACC_ERR, s); */
/* ft_printf("strerror:%s\n", strerror(errno)); */
ft_dprintf(2, "ls: ");
perror(s);
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_MSG_FILE_ERR, s); */
/* ft_printf("strerror:%s\n", strerror(errno)); */
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);
}

View file

@ -6,13 +6,13 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 14:59:51 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:50:52 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:31:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
int ft_ls_long_middle(struct stat *stat, t_pads *pads)
int ft_ls_long_middle(struct stat *stat, t_pads *pads, int opts)
{
struct passwd *pwd;
struct group *grp;
@ -21,9 +21,13 @@ int ft_ls_long_middle(struct stat *stat, t_pads *pads)
return (1);
if ((grp = getgrgid(stat->st_gid)) == NULL)
return (1);
ft_printf(" %*hu", pads->nlink, stat->st_nlink);
ft_printf(" %-*s", pads->name, pwd->pw_name);
ft_printf(" %-*s", pads->gr_name, grp->gr_name);
ft_printf(" %*hu ", pads->nlink, stat->st_nlink);
if (!(opts & OPTS_LG))
ft_printf("%-*s", pads->name, pwd->pw_name);
if (!(opts & (OPTS_LO | OPTS_LG)))
ft_putstr(" ");
if (!(opts & OPTS_LO))
ft_printf("%-*s", pads->gr_name, grp->gr_name);
if (S_ISBLK(stat->st_mode) || S_ISCHR(stat->st_mode))
ft_printf(" % *i,% *i",
pads->major + 1, major(stat->st_rdev),
@ -35,11 +39,8 @@ int ft_ls_long_middle(struct stat *stat, t_pads *pads)
void ft_ls_long_date(struct stat *stat, int opts)
{
char *date;
char *day;
char *month;
char *time;
time_t st_time;
time_t st_time;
t_mytime *time;
if (opts & OPTS_LC)
st_time = stat->st_ctime;
@ -49,20 +50,15 @@ void ft_ls_long_date(struct stat *stat, int opts)
st_time = stat->st_birthtime;
else
st_time = stat->st_mtime;
date = ctime(&st_time);
/* ft_printf("\nctime is:%s\n", date); */
month = ft_strsub(date, 4, 3);
day = ft_strsub(date, 8, 2);
if (ft_time_isrecent(st_time))
time = ft_strsub(date, 11, 5);
else if (ft_isdigit(date[20]))
time = ft_strsub(date, 20, 4);
time = ft_mytime_get(st_time);
if (opts & OPTS_UT)
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);
else
time = ft_strsub(date, 23, 6);
ft_printf(" %s %s %5s", month, day, time);
free(month);
free(day);
free(time);
ft_printf(" %s %s %s", time->month, time->day, time->year);
ft_mytime_free(&time);
}
void ft_ls_long_type(mode_t m)

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:01:01 by jhalford #+# #+# */
/* Updated: 2016/11/23 16:19:43 by jhalford ### ########.fr */
/* Updated: 2016/11/25 17:22:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -53,16 +53,17 @@ int ft_ls_long_lnk(t_lsdata *data)
int ft_ls_long_xattr(mode_t m, char *path)
{
int n;
char x;
char x;
acl_t acl;
acl_entry_t acl_entry;
x = ' ';
n = 0;
if (!S_ISBLK(m) && !S_ISCHR(m))
if ((n = ft_xattr_count(path)) == -1)
;
if (n > 0)
x = '@';
acl = acl_get_file(path, ACL_TYPE_DEFAULT | ACL_TYPE_ACCESS);
if ((acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry)) == 0)
x = '+';
else if (!S_ISBLK(m) && !S_ISCHR(m))
x = ft_xattr_count(path) > 0 ? '@' : ' ';
else
x = ' ';
ft_putchar(x);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 14:59:09 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:49:44 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:26:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,14 +17,15 @@ void ft_lsdata_filename(t_lsdata *data, t_lsdata *topdir, int opts)
struct dirent *dirent;
dirent = data->dirent;
if (opts & OPTS_UG)
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);
else
ft_printf("noname!");
if (opts & OPTS_LP && S_ISDIR(data->stat.st_mode))
ft_putchar('/');
if (opts & OPTS_UG)
ft_color_reset();
ft_ls_postname(data->stat.st_mode, opts);
}
int ft_lsdata_cmp_name(t_lsdata *dat1, t_lsdata *dat2)
@ -43,7 +44,7 @@ int ft_lsdata_cmp0(t_lsdata *data, char *dataref)
return (*filename != *dataref);
}
int ft_lsdata_cmpA(t_lsdata *data, char *dataref)
int ft_lsdata_cmpa(t_lsdata *data, char *dataref)
{
char *filename;

View file

@ -6,12 +6,37 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:02:46 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:46:50 by jhalford ### ########.fr */
/* Updated: 2016/11/25 18:31:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
t_opts g_opts[] =
{
{'A', OPTS_UA, 0},
{'F', OPTS_UF, OPTS_LP},
{'G', OPTS_UG, 0},
{'R', OPTS_UR, 0},
{'S', OPTS_US, 0},
{'T', OPTS_UT, 0},
{'U', OPTS_UU, TIME_MASK},
{'a', OPTS_LA, 0},
{'c', OPTS_LC, 0},
{'d', OPTS_LD, 0},
{'f', OPTS_LF, 0},
{'g', OPTS_LG, 0},
{'l', OPTS_LL, 0},
{'o', OPTS_LO, 0},
{'p', OPTS_LP, OPTS_UF},
{'r', OPTS_LR, 0},
{'t', OPTS_LT, 0},
{'u', OPTS_LU, TIME_MASK},
{'1', OPTS_ONE, (OPTS_LL | OPTS_LG | OPTS_LO)},
{0, 0, 0},
};
static void ft_ls_parse_files(int ac, char **av, int opts, t_list **dir, t_list **ent)
{
t_lsdata data;
@ -22,13 +47,11 @@ static void ft_ls_parse_files(int ac, char **av, int opts, t_list **dir, t_list
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)
{
@ -46,65 +69,22 @@ static void ft_ls_parse_files(int ac, char **av, int opts, t_list **dir, t_list
static int ft_getopts(char *str)
{
int i;
int j;
int opts;
i = 0;
opts = 0;
while (str[i])
{
if (str[i] == 'l')
{
opts |= OPTS_LL;
opts &= ~OPTS_ONE;
}
else if (str[i] == '1')
{
opts |= OPTS_ONE;
opts &= ~OPTS_LL;
}
else if (str[i] == 'a')
opts |= OPTS_LA;
else if (str[i] == 'c')
{
opts &= ~TIME_MASK;
opts |= OPTS_LC;
}
else if (str[i] == 'f')
{
opts |= OPTS_LF;
opts |= OPTS_LA;
}
else if (str[i] == 't')
opts |= OPTS_LT;
else if (str[i] == 'r')
opts |= OPTS_LR;
else if (str[i] == 'd')
{
opts &= ~OPTS_UR;
opts |= OPTS_LD;
}
else if (str[i] == 'p')
opts |= OPTS_LP;
else if (str[i] == 'u')
{
opts &= ~TIME_MASK;
opts |= OPTS_LU;
}
else if (str[i] == 'A')
opts |= OPTS_UA;
else if (str[i] == 'R')
{
if (!(opts & OPTS_LD))
opts |= OPTS_UR;
}
else if (str[i] == 'U')
{
opts &= ~TIME_MASK;
opts |= OPTS_UU;
}
else if (str[i] == 'S')
opts |= OPTS_US;
else
j = -1;
while (g_opts[++j].id)
if (g_opts[j].id == str[i])
{
opts &= ~g_opts[j].off;
opts |= g_opts[j].on;
break ;
}
if (!ft_strchr(LS_LEGAL_OPTS, str[i]))
{
ft_error_option(str[i]);
exit(1);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:00:15 by jhalford #+# #+# */
/* Updated: 2016/11/23 18:20:34 by jhalford ### ########.fr */
/* Updated: 2016/11/25 10:49:54 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */