first commit
This commit is contained in:
commit
c3b3e400a5
10 changed files with 174 additions and 0 deletions
3
ls/.gitmodules
vendored
Normal file
3
ls/.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "libft"]
|
||||||
|
path = libft
|
||||||
|
url = http://github.com/jzck/libft
|
||||||
6
ls/.tags
Normal file
6
ls/.tags
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
Mmain src/main.c /^int main(int ac, char **av)$/
|
||||||
|
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 src/lib_print.c /^void ft_ls(t_list **dirs_p)$/
|
||||||
|
ft_parse_ls src/lib_parse.c /^void ft_parse_ls(int ac, char **av, t_list **dirs,/
|
||||||
|
ft_parse_ls_options src/lib_parse.c /^int ft_parse_ls_options(int ac, char **av, char */
|
||||||
50
ls/Makefile
Normal file
50
ls/Makefile
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
NAME = ft_ls
|
||||||
|
CC = gcc
|
||||||
|
TAGFILE = .tags
|
||||||
|
|
||||||
|
D_SRC = src
|
||||||
|
F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
|
||||||
|
DF_SRC := $(addprefix $(D_SRC)/, $(F_SRC))
|
||||||
|
|
||||||
|
D_OBJ = obj
|
||||||
|
F_OBJ = $(F_SRC:.c=.o)
|
||||||
|
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
||||||
|
|
||||||
|
D_INC = includes libft/includes
|
||||||
|
O_INC = $(addprefix -I, $(D_INC))
|
||||||
|
|
||||||
|
W_FLAGS = -Wall -Wextra -Werror
|
||||||
|
D_FLAGS =
|
||||||
|
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
RM = /bin/rm -rf
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re tags test libft
|
||||||
|
|
||||||
|
all: libft $(NAME) $(TAGFILE)
|
||||||
|
|
||||||
|
test:
|
||||||
|
gcc -Iincludes main.c libftprintf.a
|
||||||
|
|
||||||
|
$(TAGFILE): $(D_SRC)/*.c
|
||||||
|
@ctags -f $(TAGFILE) $(addprefix $(D_SRC)/, $(F_SRC))
|
||||||
|
@echo "Making tags..."
|
||||||
|
|
||||||
|
$(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC)
|
||||||
|
@$(MKDIR) $(D_OBJ)
|
||||||
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
|
libft:
|
||||||
|
@$(MAKE) -C libft/ 2>/dev/null
|
||||||
|
|
||||||
|
$(NAME): $(DF_OBJ) libft/libft.a
|
||||||
|
$(CC) $(O_INC) -Llibft -lft $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(D_OBJ)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
$(RM) $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
BIN
ls/ft_ls.fr.pdf
Normal file
BIN
ls/ft_ls.fr.pdf
Normal file
Binary file not shown.
15
ls/includes/ftls.h
Normal file
15
ls/includes/ftls.h
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef FTLS_H
|
||||||
|
# define FTLS_H
|
||||||
|
# define ALL_OPTS "lRart"
|
||||||
|
# include "libft.h"
|
||||||
|
# include <dirent.h>
|
||||||
|
|
||||||
|
int ft_parse_ls_options(int ac, char **av, char *opts);
|
||||||
|
void ft_parse_ls(int ac, char **av, t_list **dirs, char * opts);
|
||||||
|
|
||||||
|
void ft_ls(t_list **dirs);
|
||||||
|
|
||||||
|
void ft_error_option(char c);
|
||||||
|
void ft_error_dir(char *s);
|
||||||
|
|
||||||
|
#endif
|
||||||
1
ls/libft
Submodule
1
ls/libft
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 55497a8a27b8f6ef48d629f0ed0e381a8130db3f
|
||||||
12
ls/src/lib_error.c
Normal file
12
ls/src/lib_error.c
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "ftls.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void ft_error_option(char c)
|
||||||
|
{
|
||||||
|
ft_printf("warning option '%c' is unsupported\n", c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_error_dir(char *s)
|
||||||
|
{
|
||||||
|
ft_printf("ls: %s: no such file or directory\n", s);
|
||||||
|
}
|
||||||
56
ls/src/lib_parse.c
Normal file
56
ls/src/lib_parse.c
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "ftls.h"
|
||||||
|
|
||||||
|
void ft_parse_ls(int ac, char **av, t_list **dirs, char *opts)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
|
(void)dirs;
|
||||||
|
i = ft_parse_ls_options(ac, av, opts);
|
||||||
|
ft_printf("options: %s\n", opts);
|
||||||
|
ft_strlsort(av + i, ac - i, &ft_strcmp);
|
||||||
|
if (i == ac)
|
||||||
|
ft_lstadd(dirs, ft_lstnew(opendir("."), sizeof(*dir)));
|
||||||
|
while (i < ac)
|
||||||
|
{
|
||||||
|
dir = opendir(av[i]);
|
||||||
|
if (dir)
|
||||||
|
{
|
||||||
|
ft_lstadd(dirs, ft_lstnew(dir, sizeof(*dir)));
|
||||||
|
/* ft_printf("found dir %s\n", av[i]); */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_error_dir(av[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_parse_ls_options(int ac, char **av, char *opts)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (i < ac)
|
||||||
|
{
|
||||||
|
if (av[i][0] == '-' && av[i][1] != '\0')
|
||||||
|
{
|
||||||
|
j = 1;
|
||||||
|
while(av[i][j])
|
||||||
|
{
|
||||||
|
if (ft_strchr(ALL_OPTS, av[i][j]))
|
||||||
|
{
|
||||||
|
if (!ft_strchr(opts, av[i][j]))
|
||||||
|
ft_strcat(opts, av[i] + j);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_error_option(av[i][j]);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
16
ls/src/lib_print.c
Normal file
16
ls/src/lib_print.c
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include "ftls.h"
|
||||||
|
|
||||||
|
void ft_ls(t_list **dirs_p)
|
||||||
|
{
|
||||||
|
t_list *ents;
|
||||||
|
struct dirent *dirent;
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
|
ents = NULL;
|
||||||
|
dir = (*dirs_p)->content;;
|
||||||
|
while ((dirent = readdir(dir)))
|
||||||
|
{
|
||||||
|
ft_lstadd(&ents, ft_lstnew(dirent, sizeof(*dirent)));
|
||||||
|
}
|
||||||
|
*dirs_p = (*dirs_p)->next;
|
||||||
|
}
|
||||||
15
ls/src/main.c
Normal file
15
ls/src/main.c
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include "ftls.h"
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
t_list *dirs;
|
||||||
|
char *opts;
|
||||||
|
|
||||||
|
dirs = NULL;
|
||||||
|
opts = (char *)malloc(sizeof(char) * 7);
|
||||||
|
ft_bzero(opts, 7);
|
||||||
|
ft_parse_ls(ac, av, &dirs, opts);
|
||||||
|
while (dirs)
|
||||||
|
ft_ls(&dirs);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue