Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compact_ver_1.0 #1

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d7c73e5
Whatever facinet helping me with
Dec 23, 2022
a54ac64
finally done
Dec 23, 2022
592a6e0
restart
Dec 23, 2022
c6b6b05
feat:added submodule and header
Dec 18, 2022
36d79be
pipe initialization and perror setup done
Dec 18, 2022
760d27c
free the pointers
Dec 18, 2022
13ebf26
str replacement functions
Dec 18, 2022
48b6499
replace string function complicated
Dec 18, 2022
e66cf29
recoded the whole pipe as earlier approach is too complicated
Dec 19, 2022
fdf02e7
fnc created to search through env and split the cmd
Dec 19, 2022
37dec41
heredoc function created and needs to be refactored
Dec 19, 2022
22c4715
refactored the file open fnc to replace all if else
Dec 19, 2022
ec2f2bf
fixed bugs with infile and outfile
Dec 19, 2022
a7ace76
next step:fix makefile
Dec 19, 2022
50b9254
refactored the file open fnc to replace all if else
Dec 20, 2022
cec5a5c
Create README.md
mdabir1203 Dec 19, 2022
a425570
Update README.md
mdabir1203 Dec 19, 2022
84a6448
Update README.md
mdabir1203 Dec 19, 2022
b94bb32
Update README.md
mdabir1203 Dec 19, 2022
9265a06
Update README.md
mdabir1203 Dec 19, 2022
8466739
Update README.md
mdabir1203 Dec 19, 2022
b3632bb
all submodules added
Dec 20, 2022
997c05f
included header for the global variable
Dec 21, 2022
8ea6bad
lets see rebasing
Dec 23, 2022
aac2884
merging
Dec 23, 2022
26c92ea
final commit
Dec 23, 2022
0b1930b
final eval version -- compact
Dec 23, 2022
43931db
adding branch 2.0
Dec 23, 2022
bbd5956
Create README.md
mdabir1203 Dec 23, 2022
6e845cc
Update README.md
mdabir1203 Dec 23, 2022
c6daf40
Update README.md
mdabir1203 Dec 23, 2022
7906980
Update pipex.h
mdabir1203 Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.dSYM
.gitignore
Binary file removed Bug_report_Pipex.jpeg
Binary file not shown.
109 changes: 37 additions & 72 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,61 @@
# +:+ +:+ +:+ #
# By: mabbas <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/12/18 02:39:41 by mabbas #+# #+# #
# Updated: 2022/12/20 02:31:26 by mabbas ### ########.fr #
# Created: 2022/12/23 01:03:33 by mabbas #+# #+# #
# Updated: 2022/12/23 03:05:17 by mabbas ### ########.fr #
# #
# **************************************************************************** #

NAME = pipex
NAME_B = pipex_bonus
#define compiler and flags for Debugger
CC = gcc
CFLAGS = -Wall -Werror -Wextra -g
INC = -I ./includes/

LIBFT = ./libs/libft/

SRCS = src/pipex.c \
src/pipex_utils.c \
libs/gnl/get_next_line.c \
libs/gnl/get_next_line_utils.c

SRCS_B = src/pipex_bonus.c \
src/pipex_utils.c \
src/pipex_utils_bonus.c \
libs/gnl/get_next_line.c \
libs/gnl/get_next_line_utils.c

OBJS = ${SRCS:.c=.o}
OBJS_B = ${SRCS_B:.c=.o}
PROG = pipex
PROG_B = pipex_bonus

SRCS = srcs/pipex.c srcs/utils.c
OBJS = ${SRCS:.c=.o}
MAIN = srcs/pipex.c

SUBM_STATE := $(shell find libs/libft -type f && libs/gnl -type f)
SRCS_B = srcs/pipex_bonus.c srcs/utils.c srcs/utils_bonus.c
OBJS_B = ${SRCS_B:.c=.o}
MAIN_B = srcs/pipex_bonus.c

ifeq ($(SUBM_STATE),)
SUBM_FLAG = submodule
else
SUBM_FLAG =
endif
HEADER = -Iincludes

NC := \033[m
B_RED := \033[1;31m
RED := \033[0;31m
B_GREEN := \033[1;32m
GREEN := \033[0;33m
B_BLUE := \033[1;34m
BLUE := \033[0;34m
PURPLE := \033[0;35m
WHCOLOR := \033[0;40m


UNAME = $(shell uname -s)
CC = gcc
CFLAGS = -Wall -Wextra -Werror -g

ifeq ($(UNAME),Linux)
VALGRIND = valgrind -q --leak-check=full --track-origin=yes
else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo You are Mac stupid!_!')
endif
.c.o: %.o : %.c
@gcc ${CFLAGS} ${HEADER} -c $< -o $(<:.c=.o)

all: libft $(NAME)
all: ${PROG}

%.o : %.c
@$(CC) $(CFLAGS) -c $< -o $@ $(INC)
${PROG}: ${OBJS}
@echo "\033[33m----Compiling libft---"
@make re -C ./lib/libft
@$(CC) ${OBJS} -Llib/libft -lft -o ${PROG}
@echo "\033[32mPipex Compiled! (\033[31m\033[32m_\033[31m\033[32m)\n"

submodule:
git submodule init
git submodule update

libft:
@echo "____!!!$(BLUE)----- Compiling Libft------$(NC)"
@$(MAKE) -C $(LIBFT)
@$(MAKE) -C $(LIBFT) bonus
@echo "Compiling Libft: \033[1;32mOK\033[m"

bonus: ${PROG_B}

$(NAME): $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) $(LIBFT)libft.a -o $(NAME)
@echo "Pipex: \033[1;32mCOMPILED⛓️\033[m"
${PROG_B}: ${OBJS_B}
@echo "\033[33m----Compiling lib----"
@make re -C ./lib/libft
@$(CC) ${OBJS_B} -Llib/libft -lft -o pipex
@echo "\033[32mPipex Bonus Compiled!(\033[31m\033[32m_\033[31m\033[32m)\n"

clean:
@echo "$(PURPLE)🚿 Sweeping in progress $(B_RED)🚿"
@rm -f $(OBJS)
@$(MAKE) -C $(LIBFT) clean
@sleep 0.5
@echo "$(B_GREEN) Swept off 🧹🧹🧹$(NC)"
@make clean -C ./lib/libft
@rm -f ${OBJS} ${OBJS_B}

fclean: clean
@rm -f $(NAME)
@echo "$(GREEN) I am gone forever🚿🚿🚿 $(B_RED)🚿🚿 $(NC)"
fclean: clean
@make fclean -C ./lib/libft
@rm -f $(NAME)
@rm -f ${PROG}
@echo "\n\033[31mDeleting EVERYTHING! ⌐(ಠ۾ಠ)¬\n"

re: fclean all
re: fclean all

.phony: all libft clean fclean
.silent: all libft clean fclean
re_bonus: fclean bonus

.PHONY: all clean fclean re re_bonus bonus
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Pipex
Looking underneath the infamous ( | ) command and learning to execute multiple commands in one line.




## Learning Goal:

Expand All @@ -13,3 +17,28 @@
[5.]☑ File descriptors and when and what happens with stdin, stdout, stderror,

[6.]☑ usage of perror.

## Functions/Ideas yet to be discovered more:

[7.] unlink , access, strerror

[8.] How to shorten your Flags(O_CREAT) for open/close function by using void pointer.



## One basic applications of the operator is here:

<img width="574" alt="image" src="https://user-images.githubusercontent.com/66947064/209409032-814f03b1-1816-47b7-aff0-927a1110cf24.png">

## **heredoc** applications:

<img width="450" alt="image" src="https://user-images.githubusercontent.com/66947064/209409101-dca9489e-4eee-4213-90f2-4f2cd183066e.png">





## Sources Used to learn :

1. https://csnotes.medium.com/pipex-tutorial-42-project-4469f5dd5901
2. https://www.youtube.com/watch?v=6xbLgZpOBi8
1 change: 1 addition & 0 deletions b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
askdjsa
32 changes: 11 additions & 21 deletions includes/pipex.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: mabbas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 02:33:33 by mabbas #+# #+# */
/* Updated: 2022/12/21 04:18:17 by mabbas ### ########.fr */
/* Created: 2021/08/02 09:58:35 by mabbas #+# #+# */
/* Updated: 2022/12/23 02:31:56 by mabbas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,29 +15,19 @@

# include <stdlib.h>
# include <unistd.h>
# include <string.h>
# include <stdio.h>
# include <sys/wait.h>
# include <string.h>
# include <fcntl.h>
# include <errno.h>
# include "../libs/libft/libft.h"
# include "../libs/gnl/get_next_line.h"
# include "../lib/libft/libft.h"

typedef struct s_pipe
{
int fd[2];
pid_t pid1;
pid_t reader;
int in_file;
int out_file;
} t_pipe;

/** Pipe opetator initialization and file handling **/
/* Mandatory functions */
void error(void);
char *path_find(char *cmd, char **envp);
void exec(char *argv, char **envp);

int file_open(char *argv, int i);
void display(void);
char *find_path(char *cmd, char **envp);
void execute(char *argv, char **envp);
int get_next_line(char **line);
/* Bonus functions */
int open_file(char *argv, int i);
void usage(void);

#endif
50 changes: 50 additions & 0 deletions lib/libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mabbas <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/12/23 00:46:49 by mabbas #+# #+# #
# Updated: 2022/12/23 00:46:49 by mabbas ### ########.fr #
# #
# **************************************************************************** #


NAME = libft.a
SRCS = ft_isalnum.c ft_isdigit.c ft_memccpy.c ft_memcpy.c ft_putchar_fd.c\
ft_putstr_fd.c ft_strdup.c ft_strlcpy.c ft_strncmp.c ft_strtrim.c\
ft_toupper.c ft_bzero.c ft_isalpha.c ft_isprint.c ft_memchr.c\
ft_memmove.c ft_putendl_fd.c ft_split.c ft_strjoin.c ft_strlen.c\
ft_strnstr.c ft_substr.c ft_atoi.c ft_calloc.c ft_isascii.c ft_itoa.c\
ft_memcmp.c ft_memset.c ft_putnbr_fd.c ft_strchr.c ft_strlcat.c\
ft_strmapi.c ft_strrchr.c ft_tolower.c ft_atof.c
OBJS = ${SRCS:.c=.o}
SRCS_B = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c\
ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c
OBJS_B = ${SRCS_B:.c=.o}
HEADER = ./

CC = gcc
CFLAGS = -Wall -Wextra -Werror

.c.o: %.o : %.c
@${CC} ${CFLAGS} -I ${HEADER} -c $< -o $(<:.c=.o)

$(NAME): ${OBJS}
@ar rc ${NAME} ${OBJS}

all: ${NAME}

bonus: ${OBJS} ${OBJS_B}
@ar rc ${NAME} ${OBJS} ${OBJS_B}

clean:
@rm -f ${OBJS} ${OBJS_B}

fclean: clean
@rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re bonus
36 changes: 36 additions & 0 deletions lib/libft/ft_atof.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atof.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcollet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/12 15:38:52 by gcollet #+# #+# */
/* Updated: 2021/07/28 16:25:22 by gcollet ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

double ft_atof(const char *str)
{
double res;
double res2;
char *c;
int len;

c = (char *)str;
res = (double)ft_atoi(c);
while (*c && *c != '.')
c++;
if (*c == '.')
c++;
res2 = (double)ft_atoi(c);
len = ft_strlen(c);
while (len--)
res2 /= 10;
if (res >= 0)
return (res + res2);
else
return (res + -res2);
}
44 changes: 44 additions & 0 deletions lib/libft/ft_atoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcollet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/08 11:53:08 by gcollet #+# #+# */
/* Updated: 2021/05/12 17:33:21 by gcollet ### ########.fr */
/* */
/* ************************************************************************** */

/* La fonction atoi() convertit le début de la chaîne pointée par nptr en
entier de type int . */
/* VALEUR RENVOYÉE : Le résultat de la conversion. */

#include "libft.h"

int ft_atoi(const char *nptr)
{
long num;
int sign;
int i;

i = 0;
sign = 1;
num = 0;
while ((nptr[i] >= '\t' && nptr[i] <= '\r') || nptr[i] == ' ')
nptr++;
if (nptr[i] == '-')
sign = sign * -1;
if (nptr[i] == '+' || nptr[i] == '-')
nptr++;
while (nptr[i] >= '0' && nptr[i] <= '9')
{
num = (num * 10) + nptr[i] - '0';
nptr++;
if (num * sign > 2147483647)
return (-1);
if (num * sign < -2147483648)
return (0);
}
return (num * sign);
}
30 changes: 30 additions & 0 deletions lib/libft/ft_bzero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcollet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/05 15:00:08 by gcollet #+# #+# */
/* Updated: 2021/05/08 12:41:53 by gcollet ### ########.fr */
/* */
/* ************************************************************************** */

/* La fonction bzero() met à 0 (octets contenant « \0 ») les n premiers octets
du bloc pointé par s. */
/* VALEUR RENVOYÉE : Aucune. */

#include "libft.h"

void ft_bzero(void *s, size_t n)
{
char *str;

str = (char *)s;
while (n)
{
*str = 0;
str++;
n--;
}
}
Loading