|
| 1 | +<h1 align="center">PIPEX</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.com/f-corvaro/PIPEX"> |
| 5 | + <img src="https://github.com/f-corvaro/PIPEX/blob/main/.extra/pipex.png" alt="PIPEX" width="300"> |
| 6 | + </a> |
| 7 | +</p> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <b><i>"Unleash the power of Unix pipelines and redirections with PIPEX - your gateway to system programming."</i></b><br> |
| 11 | +</p> |
| 12 | +<p align="center" style="text-decoration: none;"> |
| 13 | + <a href="https://github.com/f-corvaro/PIPEX/blob/main/.extra/en.subject.pdf"><img alt="subject" src="https://img.shields.io/badge/subject-PIPEX-yellow" /></a> |
| 14 | + <a href="https://github.com/f-corvaro/PIPEX"><img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/f-corvaro/PIPEX?color=blueviolet" /></a> |
| 15 | + <a href="https://github.com/f-corvaro/PIPEX"><img alt="Code language count" src="https://img.shields.io/github/languages/count/f-corvaro/PIPEX?color=yellow" /></a> |
| 16 | + <a href="https://github.com/f-corvaro/PIPEX"><img alt="GitHub top language" src="https://img.shields.io/github/languages/top/f-corvaro/PIPEX?color=blueviolet" /></a> |
| 17 | + <a href="https://github.com/f-corvaro/PIPEX"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/f-corvaro/PIPEX?color=yellow" /></a> |
| 18 | +</p> |
| 19 | + |
| 20 | +<h3 align="center">Index</h3> |
| 21 | + |
| 22 | +<p align="center"> |
| 23 | + <a href="#pipex">PIPEX</a><br> |
| 24 | + <a href="#index">Index</a><br> |
| 25 | + <a href="#about">About</a><br> |
| 26 | + <a href="#folder-structure">Folder Structure</a><br> |
| 27 | + <a href="#mandatory-part">Mandatory part</a><br> |
| 28 | + <a href="#the-rules">The rules</a><br> |
| 29 | + <a href="#bonus-part">Bonus Part</a><br> |
| 30 | + <a href="#evaluation">Evaluation</a><br> |
| 31 | + <a href="#correction-sheet">Correction sheet</a><br> |
| 32 | + <a href="#support-me">Support Me</a><br> |
| 33 | + <a href="#skills-developed">Skills developed</a><br> |
| 34 | + <a href="#sources">Sources</a><br> |
| 35 | + <a href="#license">License</a><br> |
| 36 | + <a href="#author">Author</a> |
| 37 | +</p> |
| 38 | +<br> |
| 39 | + |
| 40 | +## Folder Structure |
| 41 | + |
| 42 | +<p align="justify"> |
| 43 | + |
| 44 | +``` |
| 45 | +``` |
| 46 | + |
| 47 | +<br> |
| 48 | + |
| 49 | +## About |
| 50 | + |
| 51 | +<p align="justify"> |
| 52 | + |
| 53 | +This project aims to create a program in C that mimics the Unix pipeline mechanism, specifically the `|` (pipe) operator. The pipe operator in Unix/Linux is used to chain multiple commands together, where the output of one command serves as input to the next. |
| 54 | + |
| 55 | +In the context of this project, you'll be expected to create a program that can take two commands as input, execute the first command, capture its output, and then provide that output as input to the second command. |
| 56 | + |
| 57 | +<p> |
| 58 | +<br> |
| 59 | + |
| 60 | +**Some rules to keep in mind:** |
| 61 | + |
| 62 | +<p align="justify"> |
| 63 | + |
| 64 | +• Your project must be written in C (in accordance with the Norm). |
| 65 | + |
| 66 | +• Your functions should not quit unexpectedly (segmentation fault, bus error, double |
| 67 | +free, etc) apart from undefined behaviors. |
| 68 | + |
| 69 | +• All heap allocated memory space must be properly freed when necessary. |
| 70 | + |
| 71 | +• You must submit a Makefile which will compile your source files to the required output with the flags -Wall, -Wextra and -Werror, use cc, and your Makefile must not relink. And the Makefile must at least contain the rules ```$(NAME), all, clean, fclean and re (bonus if you want maximum score)```. |
| 72 | + |
| 73 | +• If your project allows you to use your libft, you must copy its sources and its |
| 74 | +associated Makefile in a libft folder with its associated Makefile. Your project’s |
| 75 | +Makefile must compile the library by using its Makefile, then compile the project. |
| 76 | + |
| 77 | +•Global variables are forbidden. |
| 78 | + |
| 79 | +<p> |
| 80 | +<br> |
| 81 | + |
| 82 | +### Mandatory part |
| 83 | + |
| 84 | +**Program name:** |
| 85 | + |
| 86 | +<p align="justify"> |
| 87 | + |
| 88 | +```pipex``` Which has as arguments 4 elements: |
| 89 | + |
| 90 | +```file1 cmd1 cmd2 file2``` |
| 91 | + |
| 92 | +• file1 and file2 -> file names. |
| 93 | + |
| 94 | +• cmd1 and cmd2 -> shell commands with their parameters. |
| 95 | + |
| 96 | +</p> |
| 97 | +<br> |
| 98 | + |
| 99 | +**Files to turn in:** |
| 100 | + |
| 101 | +<p align="justify"> |
| 102 | + |
| 103 | +```Makefile, *.h, *.c``` |
| 104 | + |
| 105 | +</p> |
| 106 | +<br> |
| 107 | + |
| 108 | +**External functs. allowed:** |
| 109 | + |
| 110 | +<p align="justify"> |
| 111 | + |
| 112 | +Libft authorized, and: |
| 113 | + |
| 114 | +``` |
| 115 | +1. open, close, read, write, |
| 116 | +malloc, free, perror, |
| 117 | +strerror, access, dup, dup2, |
| 118 | +execve, exit, fork, pipe, |
| 119 | +unlink, wait, waitpid |
| 120 | +
|
| 121 | +1. ft_printf and any equivalent YOU coded |
| 122 | +``` |
| 123 | + |
| 124 | +</p> |
| 125 | +<br> |
| 126 | + |
| 127 | +***Examples:*** |
| 128 | + |
| 129 | +```shell |
| 130 | +$> < file1 cmd1 | cmd2 > file2 |
| 131 | +``` |
| 132 | + |
| 133 | +```shell |
| 134 | +$> ./pipex infile "ls -l" "wc -l" outfile |
| 135 | +``` |
| 136 | + |
| 137 | +Should behave like: ```< infile ls -l | wc -l > outfile``` |
| 138 | + |
| 139 | +```shell |
| 140 | +$> ./pipex infile "grep a1" "wc -w" outfile |
| 141 | +``` |
| 142 | + |
| 143 | +Should behave like: ```< infile grep a1 | wc -w > outfile``` |
| 144 | + |
| 145 | +<p> |
| 146 | +<br> |
| 147 | + |
| 148 | +## The rules |
| 149 | + |
| 150 | +<p align="justify"> |
| 151 | + |
| 152 | +The program should handle the errors like the shell command. |
| 153 | + |
| 154 | +<br> |
| 155 | + |
| 156 | +## Bonus Part |
| 157 | + |
| 158 | +<p align="justify"> |
| 159 | + |
| 160 | +The bonus part requires to handle multiple pipes, as this example: |
| 161 | + |
| 162 | +```shell |
| 163 | +$> ./pipex file1 cmd1 cmd2 cmd3 ... cmdn file2 |
| 164 | +``` |
| 165 | + |
| 166 | +Should behave like: ```< file1 cmd1 | cmd2 | cmd3 ... | cmdn > file2``` |
| 167 | + |
| 168 | + |
| 169 | +Furthermore, the program needs to support ```«``` and ```»``` when the first parameter is ```"here_doc"```. An example is: |
| 170 | + |
| 171 | +```shell |
| 172 | +$> ./pipex here_doc LIMITER cmd cmd1 file |
| 173 | +``` |
| 174 | + |
| 175 | +Should behave like: ```cmd << LIMITER | cmd1 >> file``` |
| 176 | +<p> |
| 177 | + |
| 178 | +## Evaluation |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | +### Correction sheet |
| 183 | + |
| 184 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex1.png"> |
| 185 | + |
| 186 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex2.png"> |
| 187 | + |
| 188 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex3.png"> |
| 189 | + |
| 190 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex4.png"> |
| 191 | + |
| 192 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex5.png"> |
| 193 | + |
| 194 | +<a href="https://github.com/f-corvaro/42.common_core/tree/main/02-pipex"><img width="650" src="https://github.com/f-corvaro/42.common_core/blob/main/02-pipex/.extra/.cs/pipex6.png"> |
| 195 | + |
| 196 | +</p> |
| 197 | +<br> |
| 198 | + |
| 199 | +## Support Me |
| 200 | + |
| 201 | +<p align="justify"> |
| 202 | +Remember to ⭐ the repository. |
| 203 | +If you want to support me:</p> |
| 204 | + |
| 205 | +<p align="center"> |
| 206 | +<a href="https://ko-fi.com/fcorvaro"><img width="180" img align="center" src="https://github.com/f-corvaro/42.common_core/blob/main/.extra/support-me-ko-fi.svg"><alt=""></a> |
| 207 | +<a href="https://github.com/sponsors/f-corvaro"><img width="180" img align="center" src="https://github.com/f-corvaro/42.common_core/blob/main/.extra/support-me-github.svg"><alt=""></a> |
| 208 | + |
| 209 | +<br> |
| 210 | + |
| 211 | +## Skills developed |
| 212 | + |
| 213 | +<p align="center"> |
| 214 | + <a href="https://skillicons.dev"> |
| 215 | + <img src="https://skillicons.dev/icons?i=git,c,vim,vscode" /> |
| 216 | + </a> |
| 217 | +</p><br> |
| 218 | + |
| 219 | +## Sources |
| 220 | + |
| 221 | +- [Visualization of a fork call in C](https://www.youtube.com/watch?v=QD9YKSg3wCc&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv). |
| 222 | + |
| 223 | +- [Calling fork multiple times](https://www.youtube.com/watch?v=94URLRsjqMQ&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=2). |
| 224 | + |
| 225 | +- [Practical use case for fork and pipe in C](https://www.youtube.com/watch?v=6u_iPGVkfZ4&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=4). |
| 226 | + |
| 227 | +- [Simulating the pipe "|" operator in C](https://www.youtube.com/watch?v=6xbLgZpOBi8&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=5). |
| 228 | + |
| 229 | +- [Communicating between processes (using pipes) in C](https://www.youtube.com/watch?v=Mqb2dVRe0uo&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=6). |
| 230 | + |
| 231 | +- [Introduction to FIFOs (aka named pipes) in C](https://www.youtube.com/watch?v=2hba3etpoJg&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=7). |
| 232 | + |
| 233 | +- [8 Design Patterns EVERY Developer Should Know](https://www.youtube.com/watch?v=tAuRQs_d9F8&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=8). |
| 234 | + |
| 235 | +- [fd, dup()/dup2() system call tutorial](https://www.youtube.com/watch?v=EqndHT606Tw&list=PLK4FY1IoDcHG-jUt93Cl7n7XLQDZ0q7Tv&index=9). |
| 236 | + |
| 237 | +- [](). |
| 238 | +<br> |
| 239 | + |
| 240 | +## License |
| 241 | +<p align="center"> |
| 242 | +<a href="https://choosealicense.com/licenses/mit/"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="MIT License"></a> |
| 243 | +<a href="https://opensource.org/licenses/"><img src="https://img.shields.io/badge/License-GPL%20v3-yellow.svg" alt="GPLv3 License"></a> |
| 244 | +<a href="http://www.gnu.org/licenses/agpl-3.0"><img src="https://img.shields.io/badge/license-AGPL-blue.svg" alt="AGPL License"></a> |
| 245 | +<br> |
| 246 | + |
| 247 | +## Author |
| 248 | + |
| 249 | +<p align="center"><a href="https://profile.intra.42.fr/users/fcorvaro"><img style="height:auto;" src="https://avatars.githubusercontent.com/u/102758065?v=4" width="100" height="100"alt=""></a> |
| 250 | +<p align="center"> |
| 251 | +<a href="mailto:fcorvaro@student.42roma.it"><kbd>Email</kbd><alt=""></a> |
| 252 | +<a href="https://github.com/f-corvaro"><kbd>Github</kbd><alt=""></a> |
| 253 | +<a href="https://www.linkedin.com/in/f-corvaro/"><kbd>Linkedin</kbd><alt=""></a> |
| 254 | +<a href="https://42born2code.slack.com/team/U050L8XAFLK"><kbd>Slack</kbd><alt=""></a> |
| 255 | + |
| 256 | +<hr/> |
0 commit comments