Compare commits

...

278 Commits

Author SHA1 Message Date
bd5e1671fc _ 2023-04-18 14:00:48 +02:00
62e887cfbd _ 2023-04-18 13:30:17 +02:00
3e7dcd1ba9 fix: heredoc work without global 2023-04-17 12:16:41 +00:00
9ab9c06593 Merge remote-tracking branch 'refs/remotes/origin/master' 2023-04-17 10:45:10 +00:00
2f6daa4ce5 fix: signal double prompt 2023-04-17 10:41:54 +00:00
b502364a67 _ 2023-04-14 19:14:31 +02:00
0b56e95868 _ 2023-04-14 16:17:35 +02:00
882a39fc94 Merge branch 'master' of https://git.chauvet.pro/starnakin/42_minishell 2023-04-14 15:54:27 +02:00
59d9ed3514 Enfin 2023-04-14 15:54:13 +02:00
058c96849b fix: signal gestion 2023-04-14 13:05:08 +00:00
37bd3efc98 fix: change sigint to sigdef 2023-04-14 12:41:59 +00:00
425fbd15cd _ 2023-04-14 14:16:09 +02:00
d3fa573054 core: add prototype of ft_split_charset_quoted 2023-04-14 11:53:17 +00:00
227d16ca53 fix: split \t in redirection 2023-04-13 13:26:52 +00:00
91ef62d8f9 core: use charset split 2023-04-11 17:01:19 +00:00
d06eb570fc OUBLIE PAS D'ENLEVER LE MAIN DANS FT_SPLIT_CHARSET.C 2023-04-11 18:49:41 +02:00
1ef3fa115e split 2023-04-11 17:49:02 +02:00
10db23e4ef CAMILLE BOUFON 2023-04-11 17:26:49 +02:00
a6a0293095 fix: ctrl + c is now support in heredoc and in normal mode 2023-04-11 13:03:42 +00:00
a48da783dd etienne fait mois des en fants 2023-04-07 15:17:45 +00:00
be1f7ebf8c clean: norm 2023-04-07 15:12:48 +00:00
e65a9f32c0 Correction 2023-04-07 13:26:05 +02:00
8a2eb85dc6 fix: signal and \t 2023-04-07 11:09:59 +00:00
5d482fc65a fix: signal 2023-04-05 15:35:52 +00:00
e0fb7f1fd0 clean: remove trash file 2023-04-05 14:16:20 +02:00
404fcaa15f fix: heredoc signal 2023-04-05 14:13:56 +02:00
fe535a21f0 fix: no exit when ft_exit return -2 2023-04-05 12:32:34 +02:00
8a245f0dd8 bozo_exit 2023-04-05 12:31:05 +02:00
f93fed5cdd _ 2023-04-05 12:24:20 +02:00
d99aa39070 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-04-05 12:21:59 +02:00
f0afd69bf6 ntm 2023-04-05 12:21:46 +02:00
5cbb6f078d fix: put old exit code to ft_exit 2023-04-05 12:20:36 +02:00
b3e9a23f32 _ 2023-04-05 12:17:16 +02:00
b1805834ec Les mendarines Lecler, en vrai ça va, Camille est aigris mais propre, en tout cas hâte Nathan se lève 2023-04-04 22:03:30 +02:00
0d231a062d fix: error messgae 2023-04-04 15:00:19 +02:00
10413e500b fix: old redirection are now closed beforce set new 2023-04-04 14:51:34 +02:00
760b8b644e clean: norm 2023-04-04 13:56:57 +02:00
fdfe1c8b95 fix: redirection file == redirection sign 2023-04-04 13:56:21 +02:00
0bf045d4ab KAN RP SEX CHATGPT SUR 2023-04-04 13:46:32 +02:00
7e0bbd1203 5 schtroumpf noir rencontre la schtroumpfette que se passe t-il? 2023-03-31 20:45:06 +02:00
b96b617e09 fix: leak fd 2023-03-31 18:49:12 +02:00
f6617e07c7 fix: leak fd 2023-03-31 18:48:19 +02:00
a7e75bb163 fix: all fds is now in childreen 2023-03-31 16:36:15 +02:00
d9ae113b94 fix: heredoc fd not closed 2023-03-31 15:32:21 +02:00
88d955fddc fix: heredoc ctrl + d close fd 2023-03-31 15:29:06 +02:00
68c945ae05 clean: norm 2023-03-31 15:25:26 +02:00
8af6b42642 fix: invalid read 'echo sfdsdfsd cchauvet' 2023-03-31 15:23:58 +02:00
46fe9caded fix: heredoc work now 2023-03-31 15:23:10 +02:00
1e00fee53c Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-31 15:04:44 +02:00
4dc8793eec Jour 83: Armand essaye de trouver des bugs sur mes builtins parfait, j'ai envie de lui casser le cul avec ma teube de 32cm mais je me retiens 2023-03-31 15:04:28 +02:00
f66ab7790e fix: 'echo '> >> < * ? [ ] | ; [ ] || && ( ) & # $ <<'' stop segfault now 2023-03-30 16:06:34 +02:00
41bbe2bc0b fix: quote closed verif 2023-03-30 15:43:57 +02:00
3374d21cad Merge branch 'master' of git.chauvet.pro:starnakin/42_minishell 2023-03-30 15:21:54 +02:00
94f55af0be Mon builtins est parfait, tout personne disant l'inverse mérité la pénitence à vie et faire tomber le savon 2023-03-30 15:16:21 +02:00
6f3b1ab918 fix: execve failed 2023-03-30 14:30:13 +02:00
6a81705b98 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-30 13:56:38 +02:00
27b8874f75 Tient Adrien aufaite comment va ton ptit frère yummi 2023-03-30 13:56:16 +02:00
cdfa81328b fix: file verif cause non close fd 2023-03-30 13:27:23 +02:00
bb00de527a Merge branch 'master' of git.chauvet.pro:starnakin/42_minishell 2023-03-30 13:13:10 +02:00
7e77c4fe48 clean: norm 2023-03-30 13:12:56 +02:00
13e455cbf4 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-30 13:12:43 +02:00
471845b565 Astuce: écouté Raoult 2023-03-30 13:12:18 +02:00
1c43d89fa1 fix: absolute path not found error message 2023-03-30 13:05:38 +02:00
a941a0138f fix: error print 2023-03-30 12:45:53 +02:00
011c801f1d fix: first cmd not found cause invalide read 2023-03-30 12:43:31 +02:00
f874ed9f7b fix: '<1 de | ls > 1' 2023-03-30 12:33:33 +02:00
dd49432d0d fix: redirection maybe final commit maybe ?? 2023-03-29 19:33:08 +02:00
1c8892983e fix: multiple invalid redirection 2023-03-29 19:23:18 +02:00
c1e61780e0 fix: compile now 2023-03-29 19:12:14 +02:00
6498031d59 clean: norm part2 (FINAL) 2023-03-29 19:07:57 +02:00
3e656abf5d fix: env file 2023-03-29 19:07:29 +02:00
a9df160295 clean: remove trashfile 2023-03-28 15:56:58 +02:00
2a0846fbf0 clean: norm part 1 2023-03-28 15:55:08 +02:00
9787d71b85 fix: invalid write fix 2023-03-28 15:51:12 +02:00
8a6a0012dc Update 'README.md' 2023-03-28 13:37:24 +00:00
4acefd9208 Update 'README.md' 2023-03-28 13:35:22 +00:00
c8c4297f8b Update 'README.md' 2023-03-28 13:33:08 +00:00
d05edefa0f Update 'README.md' 2023-03-28 13:31:54 +00:00
392c2d94d0 Update 'README.md' 2023-03-28 13:31:36 +00:00
94fa4de0a2 Update 'README.md' 2023-03-28 13:31:14 +00:00
d54cd98197 Update 'README.md' 2023-03-28 13:30:07 +00:00
147af02c6e Merge branch 'master' of git.chauvet.pro:starnakin/42_minishell 2023-03-28 15:28:37 +02:00
67e8a60423 fix: signal set exit code 2023-03-28 14:38:10 +02:00
96a5856592 Update 'README.md' 2023-03-27 14:40:24 +00:00
57dd5c9962 Update 'README.md' 2023-03-27 14:39:35 +00:00
689a4e4eb6 Update 'README.md' 2023-03-27 14:38:13 +00:00
db51c3c85b change: subject 2023-03-27 16:35:34 +02:00
c5ddcdc892 bozo 2023-03-24 15:47:06 +01:00
45fc051e9d Delete 'README' 2023-03-24 14:30:50 +00:00
e195fe2c6d readme 2023-03-24 15:30:25 +01:00
215b0dbb7e add Readme 2023-03-24 15:29:37 +01:00
22dc9776d6 fix: exit code 2023-03-22 16:07:27 +01:00
b3d060874d fix: "echo $" works 2023-03-22 14:59:19 +01:00
72ff3ba134 fix 2023-03-22 14:41:17 +01:00
086fd3bcbe fix: cat work now 2023-03-22 14:35:09 +01:00
0fa822f6db core: env var replacer 2023-03-22 14:29:32 +01:00
a58f9a0c76 fix: exit code works 2023-03-20 15:31:39 +01:00
d56aac4b25 fix: remove multiple redirection 2023-03-20 13:18:20 +01:00
96696243d0 fix: no env is now workable 2023-03-20 12:41:40 +01:00
f5940ee99e fix: waitpid infinite loop 2023-03-13 19:29:20 +01:00
ee3d535393 fix: quote verif is better 2023-03-13 19:28:46 +01:00
08261b1921 Je ne veux pas dénoncer mais 2023-03-13 16:51:56 +01:00
7ea602b12c Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-13 16:31:06 +01:00
7ffe556cd4 CORINNE J'AI CHAUD, VIENS 42 2023-03-13 16:30:45 +01:00
6ce54ea6fe fix 2023-03-13 15:34:57 +01:00
74bbbd899a fix 2023-03-13 15:34:43 +01:00
b1d827e106 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-03-13 15:12:57 +01:00
bf15a86c2e clean: remove trash file 2023-03-13 15:12:50 +01:00
1b17df6170 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-13 15:12:36 +01:00
51d7e60790 Fixed Armand, essaye de trouver un autre bug, BOZO 2023-03-13 15:12:23 +01:00
4d3c25547e fix 2023-03-13 14:23:27 +01:00
c43331dca3 Faut ajouter make bozo, bozo 2023-03-13 13:26:36 +01:00
ec752adbfa Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-13 13:09:48 +01:00
dbb39712ea File Descriptor 2 pour les erreurs de export 2023-03-13 13:09:41 +01:00
e2c43eb973 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-03-13 12:45:42 +01:00
3d68490320 fix: execve failed 2023-03-13 12:45:29 +01:00
0694b36a72 message 'exit' quand tu fais exit 2023-03-10 14:53:22 +01:00
3d62d3dde9 fix: cd is now usable 2023-03-10 13:55:17 +01:00
69fc4c573a fix: args have now a env var replacement ex: 0 -> 0 2023-03-10 13:40:20 +01:00
087a96e54b fix: non nuiltins is now startable 2023-03-10 13:34:23 +01:00
1a4ed128e7 core: merge 2023-03-10 12:37:09 +01:00
d36d9c92f5 core: rebuild of parsing and the execution 2023-03-10 12:32:39 +01:00
6c8e161a32 Norme pour tout les builtins et env, et correction export 2023-03-09 20:13:43 +01:00
f20eab31dd Norme pour tout les builtins et env, et correction export 2023-03-09 20:13:38 +01:00
86f01779cc Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-03-09 15:08:15 +01:00
c6d683a1fc BIENTOT FINI POTO PAVAAAARRDDDD 2023-03-09 15:07:42 +01:00
f956986789 BIENTOT FINI POTO PAVAAAARRDDDD 2023-03-09 15:07:36 +01:00
a18c4cae82 fix: use the bash waitpid implementation 2023-03-08 18:19:10 +01:00
5c9be2d56b fix: change default output from 0 to 1 2023-03-08 18:18:47 +01:00
15c95b45b1 fix: Makefile bon ok c ma faute j;avais oublié un flag comme un bozo 2023-03-08 15:02:31 +01:00
876c75bb92 fix: heredoc is now rightly implemented (no fork, ctrl + c support, ctrl + d support) 2023-03-07 17:48:18 +01:00
8093b250ce fix: leaks 2023-03-06 17:43:29 +01:00
2930755dd3 fix 2023-03-06 16:43:50 +01:00
3540743135 fix: infile has now quote removed and env var replacement 2023-03-06 16:06:12 +01:00
5bfc613126 fix: exit 2023-03-06 14:22:30 +01:00
686ea5d0db fix: infile/outfile work as well now 2023-03-06 13:21:22 +01:00
e7f8373b4a c la merde 2023-02-28 15:21:47 +01:00
9cbb1e139a Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:57:25 +01:00
06f6308bc4 merge 2023-02-28 14:57:16 +01:00
8ea2e6c620 SAL NEGRO 2023-02-28 14:56:28 +01:00
b2c7013cf9 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:55:18 +01:00
960daa8658 HITLER 2023-02-28 14:54:57 +01:00
7f4fd9d421 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:54:15 +01:00
da75bdbf72 SIEG HIEL 2023-02-28 14:53:56 +01:00
af7336fbf3 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:52:16 +01:00
00dc583ff8 卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍 2023-02-28 14:51:39 +01:00
4342d9a015 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:41:28 +01:00
46d30864ed MON GROS SEXE DANS LE CUL D'IDEFIXXX 2023-02-28 14:40:51 +01:00
e0e329a355 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:36:36 +01:00
6e0d7288e8 ESGIbdurifjjkigjikdthijir 2023-02-28 14:36:07 +01:00
5541a1f3fe Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:29:22 +01:00
d5eb265a3f PAS PAR LES FESSESESESESESESESESE 2023-02-28 14:28:54 +01:00
b914753c47 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:25:41 +01:00
5948237aad OBELIX: MAIS ASTERIX ARRETE TOUT DE SUITE 2023-02-28 14:25:20 +01:00
9a5cca3e2d Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 13:20:25 +01:00
00e570d92e IDEFIX: 'OUAFA FEJISGNNOE GSEJG SE GSKNLGSNKENE PAS PAR LES FESSES' 2023-02-28 13:19:52 +01:00
77620211da Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 13:17:31 +01:00
07bc37cc71 fix 2023-02-28 13:17:26 +01:00
ed546f5a8d ASTERIX IL SUCE IDEFIX DANS LES CHIOTTES 2023-02-28 13:16:10 +01:00
ca18dd4205 fix: execute own builtin 2023-02-28 13:10:02 +01:00
370e5149d5 core: exit_code work ? 2023-02-24 20:30:01 +01:00
fc82eefd7b fix: issue #3 2023-02-24 15:53:46 +01:00
51f892350a fix: bug bizarre 2023-02-24 15:51:12 +01:00
0941f3a370 fix: no command but one redirection crash 2023-02-24 13:25:29 +01:00
9f0b0f5422 add: exit cmd 2023-02-24 13:13:11 +01:00
3d66fbe9a9 NIQUE TA GROSSE MÈRE LA SALOPE PUTE PUTE -Camille Chauvet 2004/2023 2023-02-24 12:46:02 +01:00
1626424ed7 fix: main.c compile with clang 2023-02-24 11:16:35 +01:00
8e22eb210a fix: now is clang 2023-02-24 11:01:57 +01:00
57be71a168 fix: infile 2023-02-23 18:05:21 +01:00
0327d0f5d7 core: heredocs is now forked to prepare signal 2023-02-23 18:03:22 +01:00
2f386686c6 SAMANTHA EST CHAUDE 2023-02-23 17:19:25 +01:00
7728ded62d fix: empty line is now not add to the history 2023-02-23 15:21:06 +01:00
405c1937cd fix 2023-02-23 15:14:08 +01:00
b98717ae1a execution fix 2023-02-23 15:12:41 +01:00
413d75b94c Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-23 13:38:03 +01:00
4f66624667 Oubli 2023-02-23 13:37:50 +01:00
f31d805d83 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-23 13:37:42 +01:00
28fedfdd75 merge 2023-02-23 13:37:26 +01:00
0661f2fbd1 Je suis tout dur façe a Samantha 2023-02-23 13:36:26 +01:00
29a4a864c3 Bozo3 avance 2023-02-22 14:00:09 +01:00
cdde24f0d0 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-22 13:24:50 +01:00
a4befa5fa6 Finito Echo 2023-02-22 13:24:35 +01:00
94f48602d1 add: add ctrl + C support, but not work in heredoc 2023-02-22 00:26:32 +01:00
2b66ce5bc3 fix: "'''" 2023-02-21 23:55:32 +01:00
f346c5c2ce merge 2023-02-21 23:31:16 +01:00
9ace235831 teesgdmbklvr 2023-02-21 23:29:56 +01:00
4e92c03637 tetgs 2023-02-21 23:28:37 +01:00
76bc8fbfd8 fix: quoted split work now 2023-02-21 23:12:16 +01:00
916f2c3c50 fix: close fd 2023-02-21 22:38:00 +01:00
89c80e9bdb .......................prout 2023-02-21 22:26:45 +01:00
eb4a8ed663 merge 2023-02-21 22:13:08 +01:00
3fb6eb65a8 add: exitcode 2023-02-21 22:12:23 +01:00
1fdc51a668 OUAF OUAF OUAF OUAF OUAF BOUGNOUL 2023-02-21 22:10:40 +01:00
03a2cc055c Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-21 16:03:18 +01:00
a136a66522 echo.c 2023-02-21 16:03:08 +01:00
0ece156b97 fix: use own echo 2023-02-21 15:46:21 +01:00
4c45a2c603 deux tours ont despawn dans les backrooms le 11 septembres 2023-02-21 15:44:43 +01:00
b40762478a ARABIE AHLAWAKBAR 2023-02-21 15:42:05 +01:00
d7032849d6 fix: minishell rework 2023-02-21 15:32:22 +01:00
a20fa2a4c6 fix: add '\n' pwd 2023-02-21 15:12:26 +01:00
255892e12e fix: use builtin 2023-02-21 15:07:14 +01:00
96de7639cd Terrifiant Camille, par contre ses grosses fessses MIAM 2023-02-21 14:52:58 +01:00
17ece4bc7b problème de 2023-02-21 14:49:42 +01:00
73899f5905 J'ai fais des trucs pas comme toi bozo 2023-02-21 14:45:43 +01:00
373629b541 clean: norme 2023-02-21 14:38:09 +01:00
5caeed312c fix: leak 2023-02-21 14:37:41 +01:00
5e0ae80404 add: builtin makefile 2023-02-21 14:37:10 +01:00
69d6ac533b fix: add prototype create_value_by_key_dup 2023-02-21 14:36:20 +01:00
73d1f11269 clean: norm 2023-02-21 14:35:08 +01:00
e8deb0be19 fix: leak '0' creation 2023-02-21 14:34:49 +01:00
ca09c8ed26 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-21 13:45:06 +01:00
3682d0a348 NIQUE TA GROSSE MERE CAMILLE 2023-02-21 13:44:51 +01:00
e2a40e07fc add: ft_dprintf 2023-02-21 13:28:45 +01:00
cfd1dffbcf fix: minishell.h 2023-02-21 13:22:50 +01:00
55e378e2cb fix: minishell.h 2023-02-21 13:21:20 +01:00
fb8186ac78 OUAF OUAF OUAF CORRECTION MINISHELL.H 2023-02-21 13:15:58 +01:00
3ef58c0116 OUAF OUAF OUAF OUAF OUAF MINISHELL.H 2023-02-21 13:14:58 +01:00
cc74fda339 fix: '$' variable 2023-02-20 15:41:03 +01:00
7eedf74847 infile fix 2023-02-20 13:08:01 +01:00
c75c6838d6 clean 2023-02-17 19:05:33 +01:00
4b5a50d7fe fix: outfile is now perfectly removed 2023-02-17 18:51:27 +01:00
922db1e08f fix: quote remover 2023-02-17 18:28:06 +01:00
e709eb0dbb norm 2023-02-17 18:24:24 +01:00
3ce5b64420 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-17 18:23:26 +01:00
a183971a7a bozo 2023-02-17 18:23:17 +01:00
5175073708 SBEUB SBEUB ARABE 2023-02-17 17:46:12 +01:00
72f9dd39cf enlève le main dans pwd.c 2023-02-17 16:56:02 +01:00
8bd58675e9 Ajout Pwd et dans le .h 2023-02-17 16:54:58 +01:00
afd71e5ed8 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-17 16:44:04 +01:00
daaa9dea51 add: read input 2023-02-17 16:33:52 +01:00
d59562899b Ajout de Echo, a voir si il y a des bugs 2023-02-17 16:03:28 +01:00
fa37938073 fix: heredoc will not have history 2023-02-17 14:40:57 +01:00
7bec120312 fix: env filler variable do not exist cause invalid read 2023-02-17 13:42:53 +01:00
6090784c02 add: env_to_strs support for execve 2023-02-17 13:27:40 +01:00
d4cead2b0f clean: .env_fill.c.swp remove 2023-02-17 13:25:37 +01:00
61cd1209ff Merge branch 'master' into camille 2023-02-17 13:24:52 +01:00
6ecb66a60e clean 2023-02-17 13:24:43 +01:00
642af26133 fix: leak with > but no file 2023-02-17 13:21:50 +01:00
38e1b9834f Merge branch 'camille' 2023-02-17 13:08:06 +01:00
e31fff5137 bozo 2023-02-17 13:07:10 +01:00
8b771d6615 Ajout d'une fonction t_list -> char** nommé 'env_to_strs' 2023-02-17 13:06:16 +01:00
96da8e54c3 add: env variable support, but invalid read for a non existant variable 2023-02-16 18:28:10 +01:00
e48ee8b693 fix: empty line, leaks, pipe 2023-02-16 16:29:46 +01:00
f20038e37b merge wallah ct chaud 2023-02-16 15:19:28 +01:00
edbd267c0d merge 2023-02-16 15:17:32 +01:00
de8dfc41d4 merge 2023-02-16 15:13:55 +01:00
82a0af80ad merge: remove env to pre 2023-02-16 15:10:40 +01:00
c44530728c fix: pipe alone fix 2023-02-16 14:54:19 +01:00
1fb6e0a2c1 Bon j'ai un peu ranger mais bon voila 2023-02-16 14:30:49 +01:00
02f5815485 Bon il faut ranger la chambre sinon impec 2023-02-16 14:30:28 +01:00
22b7a4feea fix: quote infinit loop 2023-02-16 13:53:49 +01:00
8366b63821 clean: remove useless file 2023-02-15 21:34:23 +01:00
0ba212410f fix: remove useless print 2023-02-15 21:33:19 +01:00
56eead9241 fix: empty input segfault 2023-02-15 21:31:49 +01:00
99fdd578e9 fix quote je pense ca marche 2023-02-15 20:52:27 +01:00
c5467769d9 work 2023-02-14 17:11:39 +01:00
b20d4e0ddc bozo 2023-02-14 13:55:02 +01:00
afaf34f869 bozo 2023-02-14 13:54:41 +01:00
8283472d2e Merge branch 'camille' of git.chauvet.pro:starnakin/minishell into camille 2023-02-14 13:39:22 +01:00
402b6e875e start execution implementation 2023-02-14 13:38:40 +01:00
1423d42583 rename function 2023-02-14 07:33:02 +01:00
78b66b539d Merge branch 'master' into camille 2023-02-14 07:27:41 +01:00
67fb6d0533 -m 2023-02-14 07:26:18 +01:00
4533b7a75d remove testfile 2023-02-14 07:22:29 +01:00
cf4bacd42e merge master and camille 2023-02-14 07:21:24 +01:00
6ab114eeeb fix and free 2023-02-14 07:08:25 +01:00
7b3389c75d Tient Camille 0 bug whula 2023-02-10 13:19:28 +01:00
1a04f73b49 start of excution implementation 2023-02-09 18:47:05 +01:00
4258c1da62 c'est vraiment le bordel j'ai rien test mais amdoulah ca passe 2023-02-06 20:41:10 +01:00
b8017175e8 heredoc support 2023-02-03 16:02:52 +01:00
3654ff91bb chackie michel 2023-02-02 18:40:41 +01:00
4f77dde859 ca compile mtn 2023-02-02 18:26:09 +01:00
13d412ea71 Push sur ta branche 2023-02-02 17:40:09 +01:00
1d9d538e8d clean 2023-02-02 17:28:01 +01:00
ece97a4882 fclean 2023-02-02 17:27:40 +01:00
088a3be5eb in file & out file work prety well 2023-02-02 17:27:26 +01:00
33cccda0ad start 2023-02-01 17:28:38 +01:00
1533fb8c65 0.1 2023-02-01 17:08:02 +01:00
88 changed files with 3296 additions and 148 deletions

View File

@ -1,4 +1,31 @@
SRCS = main.c
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_charset_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c ./utils/ft_get_executable.c ./utils/fd.c
BUILTINS_SRC = builtins/pwd.c \
builtins/export.c \
builtins/env.c \
builtins/cd.c \
builtins/exit.c \
builtins/unset.c \
builtins/echo.c
SRCS = ${BUILTINS_SRC} \
${UTILS_SRC} \
main.c \
./cmd/cmd.c \
./env/env1.c \
./env/env2.c \
./env/env3.c \
./env/env_fill.c \
./data/data.c \
./execution/execution.c \
./syntax/syntax.c \
./format/format.c \
./redirection/heredoc.c \
./redirection/file.c \
./redirection/redirection.c \
./redirection/check.c \
./parse/parse.c \
./signal/signal.c
OBJS = ${SRCS:.c=.o}
@ -6,7 +33,7 @@ NAME = minishell
CC = clang
CFLAGS = -Wall -Werror -Wextra
CFLAGS = -Werror -Wextra -Wall -g
LIBS = libftx/libftx.a
@ -16,7 +43,8 @@ LIBS = libftx/libftx.a
all: ${NAME}
${NAME}: ${OBJS}
${CC} ${OBJS} -o ${NAME} ${LIBS}
make -C libftx all
${CC} ${OBJS} -o ${NAME} ${LIBS} -lreadline
clean:
make -C libftx clean
@ -26,7 +54,8 @@ fclean: clean
make -C libftx fclean
rm -f ${NAME}
re: fclean all
re: fclean
make all
.PHONY: all clean fclean re

34
bozoshell.h Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bozoshell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/04/14 16:16:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BOZOSHELL_H
# define BOZOSHELL_H
# include "./env/env.h"
# include "./cmd/cmd.h"
# include "./parse/parse.h"
# include "./syntax/syntax.h"
# include "./execution/execution.h"
# include "./builtins/builtins.h"
# include "./format/format.h"
# include "./redirection/redirection.h"
# include "./libftx/libftx.h"
# include "./utils/utils.h"
# include "./data/data.h"
# include "./signal/signal.h"
# include <stdio.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <signal.h>
# include <sys/types.h>
# include <sys/wait.h>
#endif

Binary file not shown.

26
builtins/builtins.h Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
/* Updated: 2023/04/18 12:57:36 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTINS_H
# define BUILTINS_H
# include "../libftx/libft/list.h"
int echo(int fd, char **strs);
int pwd(int fd);
char *get_pwd(void);
int print_env(t_list **env, int fd);
int ft_export(t_list **env, char **args, int fd);
int move_folder(char **args, t_list **env, int fd);
int unset(t_list **env, char **args, int fd);
int ft_exit(char **args, int err);
#endif

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
/* Updated: 2023/04/18 12:57:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTINS_PRIVATE_H
# define BUILTINS_PRIVATE_H
# include <limits.h>
# include "../libftx/libftx.h"
# include "../env/env.h"
# include "../utils/utils.h"
char *get_pwd(void);
#endif

62
builtins/cd.c Normal file
View File

@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
/* Updated: 2023/04/18 13:22:22 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int make_move(char *path, t_list **env)
{
char *join;
char *old;
join = ft_strjoin("/", path);
join = ft_strfjoin(get_pwd(), join);
old = get_pwd();
if (chdir(join) == 0)
{
set_value_by_key("OLDPWD", old, env);
set_value_by_key("PWD", get_pwd(), env);
free(join);
return (0);
}
free(old);
free(join);
write(2, "cd: No such file or directory\n", 30);
return (1);
}
int move_folder(char **args, t_list **env)
{
char *path;
char *old;
if (args[0] == NULL || args[1] != NULL)
{
write(2, "cd: Wrong number's argument\n", 28);
return (1);
}
path = args[0];
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
{
old = get_pwd();
if (chdir(path) == 0)
{
set_value_by_key("OLDPWD", old, env);
set_value_by_key("PWD", get_pwd(), env);
return (0);
}
free(old);
write(2, "cd: No such file or directory\n", 30);
return (1);
}
else
return (make_move(path, env));
}

63
builtins/echo.c Normal file
View File

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
/* Updated: 2023/04/11 14:57:00 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int is_space(char c)
{
return (c == ' ' || c == '\f' || c == '\v' || c == '\t'
|| c == '\r' || c == '\n');
}
int check_argument(char *str, int *check_backslash_n)
{
int i;
i = -1;
while (str[++i])
if (str[i] != '-' && str[i] != 'n')
return (1);
if (ft_strnstr(str, "n", ft_strlen(str)) && str[0] == '-')
*check_backslash_n = 1;
else
return (1);
return (0);
}
int echo(int fd, char **strs)
{
int check_backslash_n;
int check_start_write;
int i;
int y;
check_backslash_n = 0;
check_start_write = 0;
i = -1;
while (strs[++i])
{
y = -1;
while (is_space(strs[i][++y]))
;
if (check_start_write == 1
|| check_argument(strs[i], &check_backslash_n))
{
check_start_write = 1;
ft_putstr_fd(strs[i], fd);
if (strs[i + 1] != NULL)
write(fd, " ", 1);
}
}
if (!check_backslash_n)
write(fd, "\n", 1);
return (0);
}

32
builtins/env.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
/* Updated: 2023/03/30 15:15:04 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int print_env(t_list **env, int fd)
{
t_list *current;
current = *env;
while (current->next != NULL)
{
if (((t_env *)(current->content))->value)
{
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\n", 1);
}
current = current->next;
}
return (0);
}

43
builtins/exit.c Normal file
View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
/* Updated: 2023/04/05 12:30:46 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
static int error(int err, char *reason, char *problem)
{
ft_putstr_fd("bozoshell: bozo_exit ", 2);
if (problem != NULL)
{
ft_putstr_fd(problem, 2);
write(2, ": ", 3);
}
ft_putstr_fd(reason, 2);
return (err);
}
int ft_exit(char **args, int err)
{
if (args[0] == NULL)
{
write(1, "bozo_exit\n", 10);
return (err);
}
err = ft_atoi_check(args[0]);
if (err == 1)
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
if (args[1] != NULL)
return (error(-1, "bozo_exit: too many arguments\n", NULL));
if (err > 0)
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
write(1, "exit\n", 6);
return ((ft_atoi(args[0]) % 256 + 256) % 256);
}

114
builtins/export.c Normal file
View File

@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/04/14 19:12:10 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
static int error(char *str, char *to_free1, char *to_free2)
{
write(2, "bozoshell: export: `", 20);
write(2, str, ft_strlen(str));
write(2, "': not a valid identifier\n", 26);
if (to_free1 != NULL)
free(to_free1);
if (to_free2 != NULL)
free(to_free2);
return (1);
}
void print_export(t_list **env, int fd)
{
t_list *current;
current = *env;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)(current->content))->key, "_"))
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
if (((t_env *)(current->content))->value != NULL)
{
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
}
else
write(fd, "\n", 2);
}
current = current->next;
}
}
int set_key_value_export(t_list **env, char *args, char **key, char **value)
{
*key = ft_strndup(args, ft_strnchr(args, '='));
if (*key == NULL)
return (1);
if (ft_strlen(*key) == 0)
return (1);
if (possible_key(*key) == 2)
{
(*key)[ft_strlen(*key) - 1] = '\0';
if (get_value_by_key(*key, env) == NULL)
*value = ft_strdup(ft_strchr(args, '=') + 1);
else
*value = ft_strjoin(get_value_by_key(*key, env),
ft_strchr(args, '=') + 1);
}
else
*value = ft_strdup(ft_strchr(args, '=') + 1);
return (0);
}
int add_export(t_list **env, char *args)
{
char *key;
char *value;
if (ft_strchr(args, '=') != NULL)
{
if (set_key_value_export(env, args, &key, &value))
return (error(args, key, NULL));
}
else
{
key = ft_strdup(args);
value = get_value_by_key(key, env);
if (value != NULL)
value = ft_strdup(value);
if (possible_key(key) == 2)
return (error(key, key, value));
}
if (!possible_key(key))
return (error(args, key, value));
create_value_by_key(key, value, env);
return (0);
}
int ft_export(t_list **env, char **args, int fd)
{
int err;
int i;
err = 0;
if (args[0] == NULL)
print_export(env, fd);
else
{
i = -1;
while (args[++i])
if (add_export(env, args[i]) == 1)
err = 1;
}
return (err);
}

41
builtins/pwd.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int pwd(int fd)
{
char path[PATH_MAX];
if (getcwd(path, sizeof(path)) != NULL)
ft_putendl_fd(path, fd);
else
{
ft_putendl_fd("Error getcwd", 2);
return (1);
}
return (0);
}
char *get_pwd(void)
{
char *str;
str = ft_calloc(PATH_MAX, sizeof(char *));
if (getcwd(str, PATH_MAX) != NULL)
return (str);
else
{
ft_putendl_fd("Error getcwd", 2);
return (NULL);
}
}

35
builtins/unset.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
/* Updated: 2023/04/07 12:46:28 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int error(char *str, int fd)
{
write(fd, "bozoshell: unset: `", 19);
write(fd, str, ft_strlen(str));
write(fd, "': not a valid identifier\n", 26);
return (1);
}
int unset(t_list **env, char **args, int fd)
{
int i;
int err;
i = -1;
err = 0;
while (args[++i])
if (delete_by_key(args[i], env))
if (!possible_key(args[i]))
err = error(args[i], fd);
return (err);
}

73
cmd/cmd.c Normal file
View File

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
/* Updated: 2023/04/17 11:57:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "cmd.h"
#include "cmd_private.h"
#include "../signal/signal.h"
#include <signal.h>
void ft_cmddel(void *ptr)
{
t_cmd *content;
content = (t_cmd *) ptr;
if (content->args != NULL)
ft_freer_tab_ultimate(1, content->args);
if (content->own_cmd == false && content->executable != NULL)
free(content->executable);
if (content->fd_in[0] > 2)
close(content->fd_in[0]);
if (content->fd_out[0] > 2)
close(content->fd_out[0]);
if (content->fd_in[1] > 2)
close(content->fd_in[1]);
if (content->fd_out[1] > 2)
close(content->fd_out[1]);
free(content);
}
void ft_cmdcloser(void *ptr)
{
t_cmd *cmd;
cmd = ptr;
ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out);
}
void ft_cmdwaiter(void *ptr)
{
t_cmd *cmd;
int exit_status;
cmd = ptr;
if (cmd->executable != NULL && cmd->own_cmd == 0
&& cmd->pid != -1 && cmd->fd_in[0] != -2 && cmd->fd_out[0] != -2)
{
waitpid(cmd->pid, &exit_status, 0);
if (WIFSIGNALED(exit_status))
{
if (exit_status == 131)
{
ft_printf("Quit (core dumped)");
*ft_get_exit_code() = 131;
}
else
*ft_get_exit_code() = 130;
ft_printf("\n");
}
else
*ft_get_exit_code() = WEXITSTATUS(exit_status);
}
signal(SIGINT, ft_ctrlc);
signal(SIGQUIT, SIG_IGN);
}

32
cmd/cmd.h Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
/* Updated: 2023/04/07 15:03:53 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CMD_H
# define CMD_H
# include <stdbool.h>
# include "../data/data.h"
typedef struct s_cmd
{
int fd_in[2];
int fd_out[2];
int pid;
char *executable;
char **args;
bool own_cmd;
} t_cmd;
void ft_cmddel(void *content);
void ft_cmdwaiter(void *content);
void ft_cmdcloser(void *ptr);
#endif

21
cmd/cmd_private.h Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
/* Updated: 2023/03/31 16:33:24 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CMD_PRIVATE_H
# define CMD_PRIVATE_H
# include <sys/types.h>
# include <sys/wait.h>
# include "./cmd.h"
# include "../libftx/libftx.h"
# include "../data/data.h"
# include "../utils/utils.h"
#endif

21
data/data.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
/* Updated: 2023/04/05 14:48:30 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "./data_private.h"
#include "data.h"
int *ft_get_exit_code(void)
{
static int exit_code;
return (&exit_code);
}

26
data/data.h Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
/* Updated: 2023/04/05 14:45:23 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_H
# define DATA_H
# include "../libftx/libft/list.h"
typedef struct s_data
{
t_list **env;
t_list **cmds;
int *exit_code;
} t_data;
int *ft_get_exit_code(void);
#endif

18
data/data_private.h Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:21 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:42:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_PRIVATE_H
# define DATA_PRIVATE_H
# include "../libftx/libftx.h"
# include "./data.h"
#endif

37
env/env.h vendored Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:01 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:42:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_H
# define ENV_H
# include <stdbool.h>
# include "../libftx/libft/list.h"
# include "../data/data.h"
typedef struct s_env
{
char *key;
char *value;
} t_env;
char *ft_env_filler(t_data *data, const char *str);
void env_del(void *content);
t_list **init_env(char **env);
char **env_to_strs(t_list **head);
int create_value_by_key(char *key, char *value, t_list **head);
int create_value_by_key_dup(char *key, char *value, t_list **head);
int set_value_by_key(char *key, char *value, t_list **head);
char *get_value_by_key(char *key, t_list **head);
void env_del(void *ptr);
int delete_by_key(char *key, t_list **head);
int possible_key(char *key);
#endif

120
env/env1.c vendored Normal file
View File

@ -0,0 +1,120 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/04/18 13:57:38 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "env_private.h"
void add_sort(t_list **head, t_env *var)
{
t_list *current;
t_env *last;
current = *head;
while (current->next != NULL
&& ft_strcmp(var->key, ((t_env *)(current->content))->key) > 0)
current = current->next;
if (current->content == NULL)
current->content = var;
else
{
last = NULL;
swap_env_3((void **)&last, &current->content, (void **)&var);
while (current->next != NULL)
{
current = current->next;
swap_env(&current->content, (void **)&last);
}
}
if (current->next == NULL)
{
current->next = ft_calloc(1, sizeof(t_list));
if (!current->next)
return ;
}
}
char *get_value_by_key(char *key, t_list **head)
{
t_list *current;
current = *head;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
return (((t_env *)current->content)->value);
current = current->next;
}
return (NULL);
}
int set_value_by_key(char *key, char *value, t_list **head)
{
t_list *current;
current = *head;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
{
free(((t_env *)current->content)->value);
((t_env *)current->content)->value = value;
return (0);
}
current = current->next;
}
return (1);
}
int create_value_by_key(char *key, char *value, t_list **head)
{
t_env *content;
if (set_value_by_key(key, value, head) == 0)
{
free(key);
return (0);
}
content = ft_calloc(1, sizeof(t_env));
if (content == NULL)
return (1);
content->key = key;
content->value = value;
add_sort(head, content);
return (0);
}
t_list **init_env(char **env)
{
t_list **head;
int i;
t_env *var;
head = ft_calloc(1, sizeof(t_list *));
if (head == NULL)
return (NULL);
*head = ft_calloc(1, sizeof(t_list));
if (*head == NULL)
{
free(head);
return (NULL);
}
i = -1;
while (env[++i])
{
var = ft_calloc(1, sizeof(t_env));
if (var == NULL)
return (NULL);
var->key = get_key(env[i]);
var->value = get_value(env[i]);
add_sort(head, var);
}
return (head);
}

77
env/env2.c vendored Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
/* Updated: 2023/04/18 13:26:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "env_private.h"
int get_index(char *s, char c)
{
int i;
i = -1;
while (s[++i])
if (s[i] == c)
return (i);
return (-1);
}
void swap_env_3(void **a, void **b, void **c)
{
void *d;
d = *a;
*a = *b;
*b = *c;
*c = d;
}
void swap_env(void **a, void **b)
{
void *c;
c = *a;
*a = *b;
*b = c;
}
void env_del(void *ptr)
{
t_env *content;
if (ptr == NULL)
return ;
content = ptr;
if (content->key != NULL)
free(content->key);
if (content->key != NULL)
free(content->value);
if (content != NULL)
free(content);
}
char **env_to_strs(t_list **head)
{
t_list *current;
t_env *content;
char **env;
int i;
current = *head;
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
i = 0;
while (current->content)
{
content = current->content;
env[i++] = ft_strmerger(3, content->key, "=", content->value);
current = current->next;
}
return (env);
}

109
env/env3.c vendored Normal file
View File

@ -0,0 +1,109 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
/* Updated: 2023/04/07 13:21:54 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "env_private.h"
char *get_value(char *str)
{
char *s;
int i;
int start;
s = ft_calloc(ft_strlen(str), sizeof(char));
start = get_index(str, '=');
i = start;
while (str[++i])
s[i - start - 1] = str[i];
return (s);
}
char *get_key(char *str)
{
char *s;
int i;
s = ft_calloc(ft_strlen(str), sizeof(char));
i = -1;
while (str[++i] != '=')
s[i] = str[i];
return (s);
}
int create_value_by_key_dup(char *key, char *value, t_list **env)
{
char *key_dup;
char *value_dup;
if (set_value_by_key(key, value, env) == 0)
return (0);
key_dup = ft_strdup(key);
if (key_dup == NULL)
return (1);
if (value != NULL)
{
value_dup = ft_strdup(value);
if (value_dup == NULL)
{
free(key);
return (1);
}
}
else
value_dup = value;
if (create_value_by_key(key_dup, value_dup, env))
return (1);
return (0);
}
int delete_by_key(char *key, t_list **head)
{
t_list *last;
t_list *current;
current = *head;
last = NULL;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
{
free(((t_env *)current->content)->key);
free(((t_env *)current->content)->value);
free(current->content);
if (last && last->next)
last->next = current->next;
else
*head = current->next;
free(current);
return (0);
}
last = current;
current = current->next;
}
return (1);
}
int possible_key(char *key)
{
int i;
i = -1;
if (ft_isdigit(key[i + 1]))
return (0);
while (key[++i + 1])
if (!ft_isalnum(key[i]) && key[i] != '_')
return (0);
if (key[i] == '+')
return (2);
else if (!ft_isalnum(key[i]) && key[i] != '_')
return (0);
return (1);
}

117
env/env_fill.c vendored Normal file
View File

@ -0,0 +1,117 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env_fill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
/* Updated: 2023/04/05 15:09:46 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "./env_private.h"
static char *ft_getkey(const char *str)
{
size_t i;
char *key;
if (ft_strncmp(str, "$$", 2) == 0)
key = ft_strdup("$");
else if (ft_strncmp(str, "$?", 2) == 0)
key = ft_strdup("?");
else if (str[1] == '\0')
key = ft_strdup("");
else
{
i = 1;
while (str[i] != '\0' && !ft_is_in("$?\'\" ", str[i]))
i++;
key = ft_strndup(str + 1, i - 1);
}
if (key == NULL)
ft_eprintf("bozoshell: malloc failed\n");
return (key);
}
static char *ft_getvalue(t_data *data, char *key)
{
char *value;
if (ft_strcmp(key, "?") == 0)
value = ft_itoa(*data->exit_code);
else if (ft_strcmp(key, "$") == 0)
value = ft_strdup("PID");
else if (key[0] == '\0')
value = ft_strdup("$");
else
{
value = get_value_by_key(key, data->env);
if (value == NULL)
value = ft_strdup("");
else
value = ft_strdup(value);
}
if (value == NULL)
ft_eprintf("bozoshell: malloc failed\n");
return (value);
}
static char *ft_getvalue_by_str(t_data *data, const char *str,
size_t *key_len)
{
char *key;
char *value;
key = ft_getkey(str);
if (key == NULL)
return (NULL);
*key_len = ft_strlen(key) + 1;
value = ft_getvalue(data, key);
free(key);
return (value);
}
char *ft_str_formator(t_data *data, char *str, size_t *i)
{
char *value;
size_t key_len;
char *out;
value = ft_getvalue_by_str(data, str + *i, &key_len);
if (value == NULL)
return (NULL);
out = ft_strreplace(str, value, *i, key_len + *i);
*i = *i + ft_strlen(value);
free(value);
return (out);
}
char *ft_env_filler(t_data *data, const char *str)
{
char *out;
char *temp;
size_t i;
out = ft_strdup(str);
if (out == NULL)
return (NULL);
i = 0;
while (out[i] != '\0')
{
while (ft_is_in_quote(out, i) == 1)
i++;
while (out[i] == '$')
{
temp = ft_str_formator(data, out, &i);
if (temp == NULL)
return (NULL);
free(out);
out = temp;
}
if (out[i] != '\0')
i++;
}
return (out);
}

26
env/env_private.h vendored Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:40:24 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:40:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_PRIVATE_H
# define ENV_PRIVATE_H
# include "./env.h"
# include "../libftx/libftx.h"
# include "../utils/utils.h"
void swap_env_3(void **a, void **b, void **c);
void swap_env(void **a, void **b);
char *get_value(char *str);
char *get_key(char *str);
int get_index(char *str, char c);
char *ft_env_filler(t_data *data, const char *str);
#endif

119
execution/execution.c Normal file
View File

@ -0,0 +1,119 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
/* Updated: 2023/04/18 13:00:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "execution_private.h"
static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
{
int return_code;
if (ft_strcmp(cmd->executable, "pwd") == 0)
return_code = pwd(cmd->fd_out[0]);
else if (ft_strcmp(cmd->executable, "env") == 0)
return_code = print_env(data->env, cmd->fd_out[0]);
else if (ft_strcmp(cmd->executable, "export") == 0)
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
else if (ft_strcmp(cmd->executable, "cd") == 0)
return_code = (move_folder(cmd->args + 1, data->env, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "unset") == 0)
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "echo") == 0)
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
else
{
return_code = ft_exit(cmd->args + 1, *data->exit_code);
if (return_code >= 0)
{
*data->exit_code = return_code;
return (-2);
}
}
*data->exit_code = return_code;
return (return_code);
}
static bool ft_executor(t_data *data, t_cmd *cmd, char **env)
{
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
return (0);
cmd->pid = fork();
if (cmd->pid == -1)
return (1);
if (cmd->pid == 0)
{
signal(SIGQUIT, SIG_DFL);
signal(SIGINT, SIG_DFL);
dup2(cmd->fd_in[0], 0);
dup2(cmd->fd_out[0], 1);
ft_lstiter(*data->cmds, ft_cmdcloser);
execve(cmd->executable, cmd->args, env);
return (1);
}
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
return (0);
}
static int ft_cmd_executor(t_data *data, t_cmd *cmd)
{
int exit_code;
char **env;
if (cmd->own_cmd == 1)
{
exit_code = ft_execute_own_cmd(data, cmd);
ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out);
if (exit_code == -2)
return (1);
}
else
{
env = env_to_strs(data->env);
if (env == NULL)
return (1);
exit_code = ft_executor(data, cmd, env);
ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out);
ft_freer_tab_ultimate(1, env);
if (exit_code == 1)
return (1);
}
return (0);
}
int ft_cmds_executor(t_data *data)
{
int fds[2];
t_list *current;
t_cmd *content;
current = *data->cmds;
while (current != NULL)
{
content = current->content;
fds[0] = -1;
if (current->next != NULL)
{
if (pipe(fds) == -1)
return (1);
ft_add_fd(content->fd_out, fds[1]);
ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]);
}
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
ft_mega_closer(content->fd_in, content->fd_out);
else if (ft_cmd_executor(data, content))
return (1);
current = current->next;
}
return (0);
}

19
execution/execution.h Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:46:52 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:46:53 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXECUTION_H
# define EXECUTION_H
# include "../data/data.h"
int ft_cmds_executor(t_data *data);
#endif

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
/* Updated: 2023/04/05 15:15:56 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXECUTION_PRIVATE_H
# define EXECUTION_PRIVATE_H
# include <signal.h>
# include "../signal/signal.h"
# include "../data/data.h"
# include "../libftx/libftx.h"
# include "../cmd/cmd.h"
# include "../env/env.h"
# include "../builtins/builtins.h"
# include "../utils/utils.h"
#endif

130
format/format.c Normal file
View File

@ -0,0 +1,130 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
/* Updated: 2023/03/31 15:22:21 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "./format_private.h"
static int ft_replace(char **str, size_t i)
{
char *temp;
temp = ft_strreplace(*str, " ", i, i);
free(*str);
if (temp == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
*str = temp;
return (0);
}
static char *ft_spacer_after(const char *str)
{
char *out;
size_t i;
out = ft_strdup(str);
if (out == NULL)
return (NULL);
i = 1;
while (out[i] != '\0')
{
while (ft_is_in_quote(out, i - 1))
i++;
if (out[i - 1] == '\0' || out[i] == '\0')
break ;
if (ft_is_in("><|", out[i - 1]))
{
while (out[i] == out[i - 1])
i++;
if (ft_replace(&out, i))
return (NULL);
}
if (out[i] != '\0')
i++;
}
return (out);
}
static char *ft_spacer_before(const char *str)
{
char *out;
ssize_t i;
out = ft_strdup(str);
if (out == NULL)
return (NULL);
i = -1;
while (out[++i] != '\0')
{
while (ft_is_in_quote(out, i + 1))
i++;
if (out[i] == '\0')
break ;
if (ft_is_in("><|", out[i + 1]))
{
while (out[i] == ' ')
i++;
while (out[i] == out[i + 1])
i++;
if (ft_replace(&out, i + 1))
return (NULL);
}
}
return (out);
}
static void ft_space_simplifier(char *str)
{
size_t i;
size_t y;
i = 0;
while (str[i] != '\0')
{
if (ft_is_in_quote(str, i))
i++;
if (str[i] != '\0')
break ;
y = 0;
while (str[y + i] == ' ')
y++;
if (y > 1)
{
ft_strshift(str + i, -y + 1);
y--;
}
i++;
}
}
char *ft_formater(t_data *data, const char *str)
{
char *out;
char *temp;
if (ft_str_is_empty(str))
return (ft_strdup(" "));
temp = ft_spacer_after(str);
if (temp == NULL)
return (NULL);
out = ft_spacer_before(temp);
free(temp);
if (out == NULL)
return (NULL);
ft_space_simplifier(out);
if (out[ft_strlen(out) - 1] == ' ')
out[ft_strlen(out) - 1] = '\0';
temp = ft_env_filler(data, out);
free(out);
return (temp);
}

19
format/format.h Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:44:56 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:44:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FORMAT_H
# define FORMAT_H
# include "../data/data.h"
char *ft_formater(t_data *data, const char *str);
#endif

18
format/format_private.h Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:44:59 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:45:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FORMAT_PRIVATE_H
# define FORMAT_PRIVATE_H
# include "../libftx/libftx.h"
# include "../utils/utils.h"
#endif

View File

@ -12,7 +12,7 @@
CC = clang
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c
OBJS = $(SRCS:.c=.o)

View File

@ -28,9 +28,13 @@ char *ft_strfjoin(char *s1, char *s2);
char *ft_strmerger(size_t arg_len, ...);
int ft_is_in(char *str, char c);
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
char *ft_strndup(char *src, size_t n);
char *ft_strndup(const char *src, size_t n);
ssize_t ft_strchri(char *str, char c);
int ft_contain_only_str(char *str, char *to_find);
int ft_contain_only(char *str, char c);
int ft_strcmp(char *s1, char *s2);
void ft_swap(void *a, void *b);
void ft_swap_int(int *a, int *b);
void ft_swap_char(char *a, char *b);
#endif

View File

@ -12,7 +12,7 @@
#include "extra.h"
char *ft_strndup(char *src, size_t n)
char *ft_strndup(const char *src, size_t n)
{
char *out;
size_t i;

40
libftx/extra/ft_swap.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:25 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:43:26 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
void ft_swap(void *a, void *b)
{
void *c;
c = a;
a = b;
b = c;
}
void ft_swap_char(char *a, char *b)
{
char c;
c = *a;
*a = *b;
*b = c;
}
void ft_swap_int(int *a, int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
}

Binary file not shown.

View File

@ -36,4 +36,4 @@ fclean: clean
re: fclean all
.PHONY: all bonus clean fclean re
.PHONY: all clean fclean re

Binary file not shown.

View File

@ -45,9 +45,8 @@ SRCS = ft_isalpha.c \
ft_putchar_fd.c \
ft_putstr_fd.c \
ft_putendl_fd.c \
ft_putnbr_fd.c
BSRCS = ft_lstnew.c \
ft_putnbr_fd.c \
ft_lstnew.c \
ft_lstadd_front.c \
ft_lstsize.c \
ft_lstlast.c \
@ -59,8 +58,6 @@ BSRCS = ft_lstnew.c \
OBJS = $(SRCS:.c=.o)
BOBJS = $(BSRCS:.c=.o)
NAME = libft.a
CFLAGS = -Wall -Werror -Wextra -g
@ -73,15 +70,12 @@ all: $(NAME)
$(NAME): $(OBJS)
ar -rc $(NAME) $(OBJS)
bonus: $(OBJS) $(BOBJS)
ar -rc $(NAME) $(OBJS) $(BOBJS)
clean:
rm -f $(OBJS) $(BOBJS)
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: all bonus clean fclean re
.PHONY: all clean fclean re

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:23:35 by cchauvet #+# #+# */
/* Updated: 2023/01/05 18:54:54 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:23:01 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(int fd, char c)
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:26:36 by cchauvet #+# #+# */
/* Updated: 2022/09/29 22:43:19 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:15:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -12,7 +12,7 @@
#include "libft.h"
void *ft_cancel(char **tab, size_t len)
void *ft_cancel(void **tab, size_t len)
{
size_t i;
@ -68,7 +68,7 @@ static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
let_index++;
tab[tab_index] = ft_substr(s, start, let_index - start);
if (tab[tab_index] == NULL)
return (ft_cancel(tab, tab_index));
return (ft_cancel((void **)tab, tab_index));
tab_index++;
}
return (tab);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/01/06 19:34:13 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:22:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,8 +14,9 @@
# define LIBFT_H
# include <stdlib.h>
# include <unistd.h>
# include "./list.h"
void *ft_cancel(char **tab, size_t len);
void *ft_cancel(void **tab, size_t len);
int ft_atoi(const char *nptr);
void ft_bzero(void *s, size_t n);
void *ft_calloc(size_t nmemb, size_t size);
@ -47,25 +48,9 @@ char **ft_split(char const *s, char c);
char *ft_itoa(int n);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char*));
void ft_putchar_fd(int fd, char c);
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *nouveau);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *nouveau);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
#endif

32
libftx/libft/list.h Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:53 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:43:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIST_H
# define LIST_H
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *nouveau);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *nouveau);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
#endif

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/01/18 19:21:40 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:28:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,13 @@
# include <stdlib.h>
# include <unistd.h>
# include <stdarg.h>
# include "./libft/libft.h"
char *ft_ultoa_base(unsigned long long n, char *base);
int ft_printf(const char *format, ...);
int ft_eprintf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...);
@ -31,59 +35,46 @@ char *ft_strfjoin(char *s1, char *s2);
char *ft_strmerger(size_t arg_len, ...);
int ft_strcmp(char *s1, char *s2);
ssize_t ft_strchri(char *str, char c);
char *ft_strndup(char *src, size_t n);
char *ft_strndup(const char *src, size_t n);
void ft_swap(void *a, void *b);
void ft_swap_int(int *a, int *b);
void ft_swap_char(char *a, char *b);
void *ft_cancel(char **tab, size_t len);
int ft_atoi(const char *nptr);
void ft_bzero(void *s, size_t n);
void *ft_calloc(size_t nmemb, size_t size);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memset(void *s, int c, size_t n);
char *ft_strchr(const char *s, int c);
char *ft_strdup(const char *s);
size_t ft_strlcat(char *dst, const char *src, size_t size);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlen(const char *s);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *big, const char *little, size_t len);
char *ft_strrchr(const char *s, int c);
int ft_tolower(int c);
int ft_toupper(int c);
/* void *ft_cancel(void **tab, size_t len); */
/* int ft_atoi(const char *nptr); */
/* void ft_bzero(void *s, size_t n); */
/* void *ft_calloc(size_t nmemb, size_t size); */
/* int ft_isalnum(int c); */
/* int ft_isalpha(int c); */
/* int ft_isascii(int c); */
/* int ft_isdigit(int c); */
/* int ft_isprint(int c); */
/* void *ft_memchr(const void *s, int c, size_t n); */
/* int ft_memcmp(const void *s1, const void *s2, size_t n); */
/* void *ft_memcpy(void *dest, const void *src, size_t n); */
/* void *ft_memmove(void *dest, const void *src, size_t n); */
/* void *ft_memset(void *s, int c, size_t n); */
/* char *ft_strchr(const char *s, int c); */
/* char *ft_strdup(const char *s); */
/* size_t ft_strlcat(char *dst, const char *src, size_t size); */
/* size_t ft_strlcpy(char *dst, const char *src, size_t size); */
/* size_t ft_strlen(const char *s); */
/* int ft_strncmp(const char *s1, const char *s2, size_t n); */
/* char *ft_strnstr(const char *big, const char *little, size_t len); */
/* char *ft_strrchr(const char *s, int c); */
/* int ft_tolower(int c); */
/* int ft_toupper(int c); */
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_itoa(int n);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char*));
void ft_putchar_fd(int fd, char c);
void ft_putstr_fd(int fd, char *s);
void ft_putendl_fd(int fd, char *s);
void ft_putnbr_fd(int fd, int n);
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *nouveau);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *nouveau);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
/* char *ft_substr(char const *s, unsigned int start, size_t len); */
/* char *ft_strjoin(char const *s1, char const *s2); */
/* char *ft_strtrim(char const *s1, char const *set); */
/* char **ft_split(char const *s, char c); */
/* char *ft_itoa(int n); */
/* char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); */
/* void ft_striteri(char *s, void (*f)(unsigned int, char*)); */
/* void ft_putchar_fd(char c, int fd); */
/* void ft_putstr_fd(char *s, int fd); */
/* void ft_putendl_fd(char *s, int fd); */
/* void ft_putnbr_fd(int n, int fd); */
#endif

View File

@ -6,13 +6,13 @@
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
# Updated: 2023/01/05 18:25:05 by cchauvet ### ########.fr #
# Updated: 2023/02/01 16:19:19 by cchauvet ### ########.fr #
# #
# **************************************************************************** #
CC = clang
SRCS = ft_dprintarg.c ft_dprintflag.c ft_dprintl_base.c ft_dprintptr.c ft_dprintstrtab.c ft_dprintul_base.c ft_dprintul.c ft_dprintx.c ft_dprintX.c ft_isarg.c ft_isdigit.c ft_printf.c ft_putchar_fd.c ft_putstr_fd.c ft_skipflag.c ft_strlen.c ft_vdprintf.c
SRCS = ft_dprintarg.c ft_dprintflag.c ft_dprintl_base.c ft_dprintptr.c ft_dprintstrtab.c ft_dprintul_base.c ft_dprintul.c ft_dprintx.c ft_dprintX.c ft_isarg.c ft_isdigit.c ft_printf.c ft_putchar_fd.c ft_putstr_fd.c ft_skipflag.c ft_strlen.c ft_vdprintf.c ft_eprintf.c
OBJS = ${SRCS:.c=.o}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/23 18:08:31 by cchauvet #+# #+# */
/* Updated: 2023/01/05 17:37:12 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:29:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,13 +23,13 @@ int ft_dprintarg(int fd, int arg, va_list args)
if (arg == 'u')
return (ft_dprintul(fd, va_arg(args, unsigned int)));
if (arg == 'c')
return (ft_putchar_fd(fd, va_arg(args, int)));
return (ft_putchar_fd_p(fd, va_arg(args, int)));
if (arg == 'S')
return (ft_dprintstrtab(fd, va_arg(args, char **)));
if (arg == 's')
return (ft_putstr_fd(fd, va_arg(args, char *)));
return (ft_putstr_fd_p(fd, va_arg(args, char *)));
if (arg == '%')
return (ft_putchar_fd(fd, '%'));
return (ft_putchar_fd_p(fd, '%'));
if (arg == 'p')
return (ft_dprintptr(fd, va_arg(args, void *)));
return (0);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/10 03:26:21 by cchauvet #+# #+# */
/* Updated: 2022/10/21 15:54:31 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:30:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@ int ft_dprintl_base(int fd, long long int n, char *base)
if (n < 0)
{
nb = -n;
i += ft_putchar_fd(fd, '-');
i += ft_putchar_fd_p(fd, '-');
}
else
nb = n;

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 17:41:04 by cchauvet #+# #+# */
/* Updated: 2022/10/12 15:22:40 by cchauvet ### ########.fr */
/* Updated: 2023/02/03 12:53:45 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,10 +18,10 @@ int ft_dprintptr(int fd, void *ptr)
int i;
if (ptr == NULL)
return (ft_putstr_fd(fd, "(nil)"));
return (ft_putstr_fd_p(fd, "(nil)"));
address = (unsigned long) ptr;
i = 2;
ft_putstr_fd(fd, "0x");
ft_putstr_fd_p(fd, "0x");
i += ft_dprintul_base(fd, address, "0123456789abcdef");
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/05 17:26:55 by cchauvet #+# #+# */
/* Updated: 2023/01/05 18:52:56 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:30:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,8 +21,8 @@ int ft_dprintstrtab(int fd, char **tab)
index = 0;
while (tab[index] != NULL)
{
i += ft_putstr_fd(fd, tab[index]) + 1;
ft_putchar_fd(fd, '\n');
i += ft_putstr_fd_p(fd, tab[index]) + 1;
ft_putchar_fd_p(fd, '\n');
index++;
}
return (i);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
/* Updated: 2022/10/23 14:23:44 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:31:15 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -73,9 +73,9 @@ int ft_dprintul_base(int fd, unsigned long long n, char *base)
if (n > base_size - 1)
{
ft_dprintul_base(fd, n / base_size, base);
ft_putchar_fd(fd, base[n % base_size]);
ft_putchar_fd_p(fd, base[n % base_size]);
}
else
ft_putchar_fd(fd, base[n]);
ft_putchar_fd_p(fd, base[n]);
return (str_size - 1);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_eprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 22:01:28 by cchauvet #+# #+# */
/* Updated: 2023/02/01 16:18:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_eprintf(const char *format, ...)
{
va_list va;
int i;
va_start(va, format);
i = ft_vdprintf(2, format, va);
va_end(va);
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 22:01:28 by cchauvet #+# #+# */
/* Updated: 2022/10/12 16:34:31 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:27:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,3 +22,14 @@ int ft_printf(const char *format, ...)
va_end(va);
return (i);
}
int ft_dprintf(int fd, const char *format, ...)
{
va_list va;
int i;
va_start(va, format);
i = ft_vdprintf(fd, format, va);
va_end(va);
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/01/05 17:36:39 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:27:51 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,10 +32,12 @@ int ft_dprintarg(int fd, int c, va_list va);
int ft_dprintstrtab(int fd, char **tab);
int ft_printf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
int ft_eprintf(const char *format, ...);
int ft_vdprintf(int fd, const char *format, va_list va);
int ft_putchar_fd(int fd, char c);
int ft_putstr_fd(int fd, char *str);
int ft_putchar_fd_p(int fd, char c);
int ft_putstr_fd_p(int fd, char *str);
#endif

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:23:35 by cchauvet #+# #+# */
/* Updated: 2022/10/12 15:21:42 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:28:59 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar_fd(int fd, char c)
int ft_putchar_fd_p(int fd, char c)
{
write(fd, &c, 1);
return (1);

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:25:08 by cchauvet #+# #+# */
/* Updated: 2022/10/12 16:51:51 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:28:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putstr_fd(int fd, char *str)
int ft_putstr_fd_p(int fd, char *str)
{
int i;
@ -20,6 +20,6 @@ int ft_putstr_fd(int fd, char *str)
str = "(null)";
i = 0;
while (str[i] != '\0')
ft_putchar_fd(fd, str[i++]);
ft_putchar_fd_p(fd, str[i++]);
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 14:34:28 by cchauvet #+# #+# */
/* Updated: 2022/12/11 19:23:34 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 16:31:29 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ static int ft_dprintseg(int fd, const char *str)
i = 0;
while (str[i] != '\0' && ft_skipflag(str + i) == 0)
{
ft_putchar_fd(fd, str[i]);
ft_putchar_fd_p(fd, str[i]);
i++;
}
return (i);

Binary file not shown.

112
main.c
View File

@ -1,11 +1,115 @@
#include "minishell.h"
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/04/18 12:59:43 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
t_list **ft_parse_cmd(char *line)
#include "data/data.h"
#include "env/env.h"
#include "libftx/libft/libft.h"
#include "libftx/libft/list.h"
#include "libftx/libftx.h"
#include "bozoshell.h"
#include "signal/signal.h"
#include <stdlib.h>
static char *ft_get_user_input(void)
{
ft_split()
char *line;
char *prompt;
char *pwd;
pwd = get_pwd();
if (pwd == NULL)
return (NULL);
prompt = ft_strmerger(2, pwd, "$ ");
free(pwd);
if (prompt == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
line = readline(prompt);
if (line != NULL && ft_strcmp(line, "") != 0)
add_history(line);
free(prompt);
if (line == NULL)
ft_printf("exit\n");
return (line);
}
int main(int ac, char **av)
static int ft_minishell(t_data *data, char *line)
{
char *line_clean;
if (ft_syntax_verif(data, line))
return (0);
line_clean = ft_formater(data, line);
if (line_clean == NULL || line_clean[0] == '\0')
return (0);
if (ft_cmds_parser(data, line_clean))
{
free(line_clean);
return (0);
}
free(line_clean);
if (ft_cmds_executor(data) == 1)
return (1);
ft_lstiter(*data->cmds, ft_cmdwaiter);
ft_lstclear(data->cmds, ft_cmddel);
return (0);
}
int ft_init_data(t_data *data, char **env)
{
data->exit_code = ft_get_exit_code();
data->cmds = malloc(sizeof(t_cmd *));
if (data->cmds == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
*data->cmds = NULL;
data->env = init_env(env);
if (data->env == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
free(data->cmds);
return (1);
}
return (0);
}
int main(int ac, char **av, char **env)
{
t_data data;
char *line;
(void) ac;
(void) av;
signal(SIGINT, ft_ctrlc);
signal(SIGQUIT, SIG_IGN);
if (ft_init_data(&data, env))
return (1);
line = ft_get_user_input();
while (line != NULL)
{
if (ft_minishell(&data, line) == 1)
break ;
free(line);
line = ft_get_user_input();
if (line == NULL)
break ;
}
ft_lstclear(data.cmds, ft_cmddel);
free(data.cmds);
ft_lstclear(data.env, env_del);
free(data.env);
return (*data.exit_code);
}

View File

@ -1,20 +0,0 @@
#ifndef FT_MINISHELL
# define FT_MINISHELL
# include "libftx/libftx.h"
typedef struct s_list
{
void *content;
void *next;
int tag;
} t_list
typedef struct cmd
{
int fd_in;
int fd_out;
char *cmd;
char *args;
} cmd;
#endif

127
parse/parse.c Normal file
View File

@ -0,0 +1,127 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
/* Updated: 2023/04/11 16:17:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./parse_private.h"
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
{
char **tab;
size_t i;
tab = ft_split_charset_quoted(cmd_str, "\t ");
if (tab == NULL)
return (1);
i = 0;
while (tab[i] != NULL)
{
ft_quote_remover(tab[i]);
i++;
}
cmd->args = tab;
return (0);
}
static int ft_executable_parse(t_data *data, t_cmd *cmd)
{
bool own;
char *path;
path = cmd->args[0];
own = 0;
if (cmd->args[0] == NULL)
{
ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out);
}
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0],
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0)
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0],
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0)
|| (ft_strcmp(cmd->args[0], "cd") == 0))
own = 1;
else
{
path = ft_get_executable(data, cmd->args[0]);
if (path == NULL)
return (1);
}
cmd->own_cmd = own;
cmd->executable = path;
return (0);
}
int ft_cmd_adder(t_data *data, t_cmd *cmd)
{
t_list *element;
element = ft_lstnew(cmd);
if (element == NULL)
{
ft_cmddel(cmd);
return (1);
}
ft_lstadd_back(data->cmds, element);
return (0);
}
int ft_cmd_parser(t_data *data, char *cmd_str)
{
t_cmd *cmd;
cmd = ft_calloc(sizeof(t_cmd), 1);
if (cmd == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
if (ft_redirection(data, cmd, cmd_str))
{
ft_cmddel(cmd);
return (1);
}
if (ft_args_parse(cmd_str, cmd))
{
ft_cmddel(cmd);
return (1);
}
ft_executable_parse(data, cmd);
return (ft_cmd_adder(data, cmd));
}
int ft_cmds_parser(t_data *data, const char *line)
{
char **tab;
ssize_t i;
tab = ft_split_charset_quoted(line, "|");
if (tab == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
i = -1;
while (tab[++i] != NULL)
{
if (ft_cmd_parser(data, tab[i]))
{
ft_freer_tab_ultimate(1, tab);
return (1);
}
}
if (*data->cmds != NULL)
{
ft_add_fd(((t_cmd *)(*data->cmds)->content)->fd_in, 0);
ft_add_fd(((t_cmd *)(ft_lstlast(*data->cmds))->content)->fd_out, 1);
}
ft_freer_tab_ultimate(1, tab);
return (0);
}

19
parse/parse.h Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:38 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_H
# define PARSE_H
# include "../data/data.h"
int ft_cmds_parser(t_data *data, const char *line);
#endif

21
parse/parse_private.h Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:44 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:45 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_PRIVATE_H
# define PARSE_PRIVATE_H
# include "../redirection/redirection.h"
# include "../libftx/libftx.h"
# include "../utils/utils.h"
# include "../env/env.h"
# include "../data/data.h"
# include "../cmd/cmd.h"
#endif

151
redirection/check.c Normal file
View File

@ -0,0 +1,151 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
/* Updated: 2023/04/17 11:15:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./redirection_private.h"
#include <stdbool.h>
#include "../signal/signal.h"
#include <signal.h>
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
{
int fd;
if (ft_strcmp(redirection_identifier, "<<") == 0)
{
if (cmd->fd_in[0] == -2)
return (0);
signal(SIGINT, ft_ctrlc_heredoc);
fd = ft_heredoc(data, redirection);
signal(SIGINT, ft_ctrlc);
if (fd == -2)
return (1);
else
{
if (cmd->fd_in[0] > 2)
close(cmd->fd_in[0]);
cmd->fd_in[0] = fd;
}
}
return (0);
}
static bool ft_check_infile(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
{
int fd;
if (ft_strcmp(redirection_identifier, "<") == 0)
{
if (cmd->fd_in[0] == -2)
return (0);
if (ft_file_is_readable(data, redirection))
{
fd = open(redirection, O_RDONLY);
if (cmd->fd_in[0] > 2)
close(cmd->fd_in[0]);
cmd->fd_in[0] = fd;
}
else
{
if (cmd->fd_in[0] > 2)
close(cmd->fd_in[0]);
cmd->fd_in[0] = -2;
return (0);
}
}
return (0);
}
static bool ft_check_outfile(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
{
int fd;
if (ft_strcmp(redirection_identifier, ">") == 0)
{
if (cmd->fd_out[0] == -2)
return (0);
if (ft_file_is_writable(data, redirection))
{
fd = open(redirection,
O_WRONLY | O_TRUNC | O_CREAT, 0644);
if (cmd->fd_out[0] > 2)
close(cmd->fd_out[0]);
cmd->fd_out[0] = fd;
}
else
{
if (cmd->fd_out[0] > 2)
close(cmd->fd_out[0]);
cmd->fd_out[0] = -2;
return (0);
}
}
return (0);
}
static bool ft_check_outfile_append(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
{
int fd;
if (ft_strcmp(redirection_identifier, ">>") == 0)
{
if (cmd->fd_out[0] == -2)
return (0);
if (ft_file_is_appendable(data, redirection))
{
fd = open(redirection,
O_WRONLY | O_APPEND | O_CREAT, 0644);
if (cmd->fd_out[0] > 2)
close(cmd->fd_out[0]);
cmd->fd_out[0] = fd;
}
else
{
if (cmd->fd_out[0] > 2)
close(cmd->fd_out[0]);
cmd->fd_out[0] = -2;
}
}
return (0);
}
bool ft_check_redirection(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
{
char *str;
bool out;
if (ft_is_in("<>", redirection_identifier[0])
&& ft_is_in("<>", redirection[0]))
{
ft_eprintf("bozoshell: %s: invalid redirection file\n", redirection);
return (1);
}
str = ft_strdup(redirection);
if (str == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
ft_quote_remover(str);
out = 0;
if (ft_check_heredoc(data, cmd, redirection_identifier, str)
|| ft_check_infile(data, cmd, redirection_identifier, str)
|| ft_check_outfile(data, cmd, redirection_identifier, str)
|| ft_check_outfile_append(data, cmd, redirection_identifier, str))
out = 1;
free(str);
return (out);
}

82
redirection/file.c Normal file
View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 17:36:11 by cchauvet #+# #+# */
/* Updated: 2023/04/05 15:12:41 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "./redirection_private.h"
int ft_file_is_readable(t_data *data, const char *path)
{
int readable;
int fd;
fd = open(path, O_RDONLY);
if (fd == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: No such file or directory\n", path);
return (0);
}
readable = read(fd, "", 0);
if (readable == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0);
}
close(fd);
return (1);
}
int ft_file_is_writable(t_data *data, const char *path)
{
int writeable;
int fd;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if (fd == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0);
}
writeable = write(fd, "", 0);
if (writeable == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0);
}
close(fd);
return (1);
}
int ft_file_is_appendable(t_data *data, const char *path)
{
int writeable;
int fd;
fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644);
if (fd == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0);
}
writeable = write(fd, "", 0);
if (writeable == -1)
{
*data->exit_code = 1;
ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0);
}
close(fd);
return (1);
}

93
redirection/heredoc.c Normal file
View File

@ -0,0 +1,93 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
/* Updated: 2023/04/17 12:14:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./redirection_private.h"
#include <readline/readline.h>
#include <unistd.h>
static bool ft_fd_is_closed(int fd)
{
int fd2;
fd2 = dup(fd);
if (fd2 == -1)
return (1);
close(fd2);
return (0);
}
static int ft_format_and_write(t_data *data, const char *str, int fd)
{
char *line_clean;
line_clean = ft_env_filler(data, str);
if (line_clean == NULL)
return (1);
ft_putendl_fd(line_clean, fd);
free(line_clean);
return (0);
}
int ft_heredoc2(t_data *data, char *line, char *stop, int fds[2])
{
if (line == NULL)
{
if (ft_fd_is_closed(0))
{
close(fds[0]);
fds[0] = -2;
return (1);
}
else
{
ft_eprintf("\nbozoshell: warning: here-document at line 1%s",
"delimited by end-of-file (wanted `adfsd')\n");
return (1);
}
}
if (ft_strcmp(line, stop) == 0)
return (1);
if (ft_format_and_write(data, line, fds[1]))
{
close(fds[0]);
fds[0] = -2;
return (1);
}
return (0);
}
int ft_heredoc(t_data *data, char *stop)
{
int fds[2];
int stdin_bak;
char *line;
stdin_bak = dup(0);
if (stdin_bak == -1)
return (1);
if (pipe(fds))
{
close(stdin_bak);
return (1);
}
line = readline("> ");
while (ft_heredoc2(data, line, stop, fds) == 0)
{
free(line);
line = readline("> ");
}
free(line);
close(fds[1]);
dup2(stdin_bak, 0);
close(stdin_bak);
return (fds[0]);
}

115
redirection/redirection.c Normal file
View File

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
/* Updated: 2023/04/13 13:26:06 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "redirection_private.h"
int ft_replace_file(t_data *data, char **tab)
{
size_t i;
char *redirection;
i = 0;
while (tab[i] != NULL)
{
if (ft_is_in("<>", tab[i][0]))
{
i++;
redirection = ft_env_filler(data, tab[i]);
if (redirection == NULL)
return (1);
free(tab[i]);
tab[i] = redirection;
ft_quote_remover(tab[i]);
}
i++;
}
return (0);
}
static void ft_skip(char *str, size_t *i, ssize_t *start)
{
while (str[*i] == str[*start])
(*i)++;
while (str[*i] == ' ')
(*i)++;
while (str[*i] != '\0' && (str[*i] != ' '
|| ft_is_in_quote(str, *i)))
(*i)++;
}
static void ft_remove_redirection(char *cmd_str)
{
size_t i;
ssize_t start;
i = 0;
while (cmd_str[i] != '\0')
{
start = -1;
while ((ft_is_in_quote(cmd_str, i) || !ft_is_in("<>", cmd_str[i]))
&& cmd_str[i] != '\0')
i++;
if (ft_is_in("<>", cmd_str[i]))
start = i;
else
continue ;
ft_skip(cmd_str, &i, &start);
if (start != -1)
{
ft_strshift(cmd_str + start, -1 * (i - start));
i = start;
}
}
}
int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
{
size_t i;
i = 0;
while (tab[i + 1] != NULL)
{
if (ft_check_redirection(data, cmd, tab[i], tab[i + 1]))
return (1);
i++;
}
if (ft_is_in("<>", tab[i][0]))
{
ft_eprintf("bozoshell: %s: must be followed by a file\n", tab[i]);
return (1);
}
return (0);
}
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str)
{
char **tab;
cmd->fd_in[0] = -1;
cmd->fd_in[1] = -1;
cmd->fd_out[0] = -1;
cmd->fd_out[1] = -1;
tab = ft_split_charset_quoted(cmd_str, " \t");
if (tab == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
ft_remove_redirection(cmd_str);
if (ft_set_redirection(data, cmd, tab))
{
ft_freer_tab_ultimate(1, tab);
return (1);
}
ft_freer_tab_ultimate(1, tab);
return (0);
}

21
redirection/redirection.h Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:19 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:44:20 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDIRECTION_H
# define REDIRECTION_H
# include "../data/data.h"
# include "../cmd/cmd.h"
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str);
int *ft_get_heredoc(void);
#endif

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
/* Updated: 2023/03/29 19:19:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDIRECTION_PRIVATE_H
# define REDIRECTION_PRIVATE_H
# include <sys/stat.h>
# include <fcntl.h>
# include <stddef.h>
# include <unistd.h>
# include "../libftx/libftx.h"
# include "../data/data.h"
# include "../env/env.h"
# include "../utils/utils.h"
# include "../cmd/cmd.h"
int ft_file_is_readable(t_data *data, const char *path);
int ft_file_is_writable(t_data *data, const char *path);
bool ft_check_redirection(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection);
int ft_file_is_appendable(t_data *data, const char *path);
int ft_heredoc(t_data *data, char *stop);
#endif

36
signal/signal.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
/* Updated: 2023/04/17 11:23:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "signal_private.h"
void ft_ctrlc_heredoc(int num)
{
close(0);
ft_putchar_fd('\n', 1);
(void) num;
}
void ft_ctrlc(int num)
{
rl_replace_line("", 0);
rl_on_new_line();
ft_putchar_fd('\n', 1);
rl_redisplay();
*ft_get_exit_code() = 130;
(void) num;
}
void ft_quit(int num)
{
(void) num;
ft_printf("Quit (core dumped)\n");
}

20
signal/signal.h Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
/* Updated: 2023/04/17 11:14:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SIGNAL_H
# define SIGNAL_H
void ft_quit(int num);
void ft_ctrlc(int num);
void ft_ctrlc_heredoc(int num);
#endif

22
signal/signal_private.h Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:59:42 by cchauvet #+# #+# */
/* Updated: 2023/04/05 15:05:00 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SIGNAL_PRIVATE_H
# define SIGNAL_PRIVATE_H
# include <signal.h>
# include <stdio.h>
# include <readline/readline.h>
# include <unistd.h>
# include "../libftx/libftx.h"
# include "../data/data.h"
# include "../redirection/redirection.h"
#endif

106
syntax/syntax.c Normal file
View File

@ -0,0 +1,106 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/04/07 11:07:52 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libftx/libftx.h"
#include "../utils/utils.h"
static int ft_quote_verif(const char *str)
{
if (ft_is_in_quote(str, ft_strlen(str)))
{
ft_eprintf("bozoshell: Quote is not closed\n");
return (1);
}
else
return (0);
}
static int ft_pipe_is_alone(const char *str)
{
ssize_t i;
int check;
check = 0;
i = -1;
while (str[++i] != '\0')
{
while (str[i] == ' ' || ft_is_in_quote(str, i))
i++;
if (str[i] == '\0')
break ;
if (str[i] != '|')
check = 1;
else
{
if (check == 0)
break ;
check = 0;
}
}
if (check == 0)
ft_eprintf("bozoshell: Pipe must be followed and %s",
"preced by a command or redirection\n");
return (check == 0);
}
static int ft_special_char_dub(const char *str)
{
size_t i;
size_t y;
i = 0;
while (str[i] != '\0')
{
while (ft_is_in_quote(str, i))
i++;
if (ft_is_in("|<>", str[i]))
{
y = 0;
while (str[i] == str[i + y])
y++;
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|| (y > 1 && str[i] == '|'))
{
ft_eprintf("bozoshell: too many %s in a row\n", str);
return (1);
}
i = i + y;
}
else if (str[i] != '\0')
i++;
}
return (0);
}
static int ft_empty_verif(const char *str)
{
size_t i;
i = 0;
while (str[i] == ' ' || str[i] == '\t')
i++;
return (str[i] == '\0');
}
int ft_syntax_verif(t_data *data, const char *str)
{
if (ft_empty_verif(str))
return (1);
if (ft_quote_verif(str)
|| ft_pipe_is_alone(str)
|| ft_special_char_dub(str))
{
*data->exit_code = 2;
return (1);
}
return (0);
}

19
syntax/syntax.h Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:54 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:55 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SYNTAX_H
# define SYNTAX_H
# include "../data/data.h"
int ft_syntax_verif(t_data *data, const char *str);
#endif

40
utils/fd.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
/* Updated: 2023/03/29 18:51:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./utils.h"
#include <stdio.h>
void ft_closer(int fds[2])
{
if (fds[0] > 2)
{
close(fds[0]);
}
if (fds[1] > 2)
{
close(fds[1]);
}
}
void ft_mega_closer(int fds1[2], int fds2[2])
{
ft_closer(fds1);
ft_closer(fds2);
}
void ft_add_fd(int fds[2], int fd)
{
if (fds[0] == -1)
fds[0] = fd;
else
fds[1] = fd;
}

50
utils/ft_atoi_check.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
/* Updated: 2023/04/04 13:40:43 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
static int ft_isspace(char c)
{
if (c == ' ' || c == '\f'
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
return (1);
return (0);
}
int ft_atoi_check(const char *nptr)
{
int64_t result;
int sign;
while (ft_isspace(*nptr))
nptr++;
sign = 1;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
sign = -1;
nptr++;
}
result = 0;
while (*nptr >= '0' && *nptr <= '9')
{
result = result * 10 + (*nptr++ - '0') * sign;
if ((result < 0 && sign == 1)
|| (result > 0 && sign == -1))
return (2);
}
if (*nptr--)
return (1);
if (*nptr == '-' || *nptr == '+')
return (1);
return (0);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_change_exit_code.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/24 19:04:04 by cchauvet #+# #+# */
/* Updated: 2023/02/24 19:05:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int ft_change_exit_code(t_data *data, int new_value)
{
char *exit_code_str;
data->exit_code = new_value;
exit_code_str = ft_itoa(new_value);
if (exit_code_str == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
return (0);
}

115
utils/ft_get_executable.c Normal file
View File

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_get_executable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
/* Updated: 2023/04/05 15:09:29 by alouis-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "./utils.h"
#include <unistd.h>
char *ft_get_executable_with_path(t_data *data, const char *name)
{
char *path;
if (access(name, F_OK) != 0)
{
*data->exit_code = 127;
ft_eprintf("bozoshell: %s: No such file or directery\n", name);
return (NULL);
}
if (access(name, X_OK) != 0)
{
*data->exit_code = 126;
ft_eprintf("bozoshell: %s: permission denied\n", name);
return (NULL);
}
path = ft_strdup(name);
if (path == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
return (path);
}
static char **ft_get_paths(t_data *data, const char *name)
{
char *paths;
char **tab;
paths = get_value_by_key("PATH", data->env);
if (paths == NULL)
{
*data->exit_code = 127;
ft_eprintf("bozoshell: %s: command not found\n", name);
return (NULL);
}
tab = ft_split(paths, ':');
if (tab == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
return (tab);
}
static char *ft_file_is_executable(const char *path, const char *name)
{
char *out;
out = ft_strmerger(3, path, "/", name);
if (out == NULL)
{
ft_eprintf("bozoshell: malloc failed\n");
free(out);
return (NULL);
}
if (access(out, X_OK) == 0)
return (out);
free(out);
return (NULL);
}
static char *ft_get_executable_without_path(t_data *data, const char *name)
{
char **paths;
char *path;
size_t i;
paths = ft_get_paths(data, name);
if (paths == NULL)
return (NULL);
path = NULL;
i = 0;
while (paths[i] != NULL)
{
path = ft_file_is_executable(paths[i], name);
if (path != NULL)
break ;
i++;
}
ft_freer_tab_ultimate(1, paths);
if (path == NULL)
{
*data->exit_code = 127;
ft_eprintf("bozoshell: %s: command not found\n", name);
}
return (path);
}
char *ft_get_executable(t_data *data, const char *name)
{
char *path;
if (name[0] == '.' || name[0] == '/')
path = ft_get_executable_with_path(data, name);
else
path = ft_get_executable_without_path(data, name);
return (path);
}

40
utils/ft_is_in_quote.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
/* Updated: 2023/03/30 15:52:10 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_is_in_quote(const char *str, size_t n)
{
size_t i;
ssize_t start;
start = -1;
i = 0;
while (str[i] != '\0')
{
if (i == n)
break ;
if (str[i] == '\"' || str[i] == '\'')
{
if (start == -1)
start = i;
else if (str[i] == str[start])
start = -1;
}
i++;
}
if (start == -1)
return (0);
if (str[start] == '\'')
return (1);
return (2);
}

25
utils/ft_printn.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:43:00 by cchauvet #+# #+# */
/* Updated: 2023/02/14 14:47:27 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./utils.h"
void ft_printn(const char *str, size_t n)
{
size_t i;
i = 0;
while (i < n && str[i] != '\0')
{
ft_putchar_fd(1, str[i]);
i++;
}
}

50
utils/ft_quote_remover.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_quote_remover.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
static void ft_remove_quote_and_reset(char *str, ssize_t *start, ssize_t *stop)
{
ft_strshift(str + *start, -1);
ft_strshift(str + *stop - 1, -1);
*start = -1;
*stop = -1;
}
char *ft_quote_remover(char *str)
{
size_t i;
ssize_t start;
ssize_t stop;
start = -1;
stop = -1;
i = 0;
while (str[i] != '\0')
{
if ((str[i] == '\"' || str[i] == '\''))
{
if (start == -1)
start = i;
else if (str[i] == str[start])
stop = i;
}
if (stop != -1)
{
ft_remove_quote_and_reset(str, &start, &stop);
i = i - 1;
}
else
i++;
}
return (str);
}

View File

@ -0,0 +1,90 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_charset_quoted.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
/* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int new_strs(char ***strs, const char *to_split, int *i, int *j)
{
if (ft_strlen((*strs)[(*i)]) <= 0)
return (0);
(*i)++;
(*j) = 0;
(*strs)[(*i)] = ft_calloc(sizeof(char),
(ft_strlen(to_split) + 1));
if (!(*strs)[(*i)])
return (1);
return (0);
}
int get_strs(const char *to_split, const char *charset, char ***strs, int *i)
{
int j;
int x;
int y;
int check;
x = -1;
j = 0;
while (to_split[++x])
{
y = -1;
check = 1;
while (charset[++y])
{
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
{
check = 0;
if (new_strs(strs, to_split, i, &j))
return (1);
}
}
if (check)
(*strs)[(*i)][j++] = to_split[x];
}
return (0);
}
void free_set_null(char ***strs, int i)
{
if (ft_strlen((*strs)[i]) == 0)
{
free((*strs)[i]);
(*strs)[i] = NULL;
}
}
char **ft_split_charset_quoted(const char *to_split, const char *charset)
{
char **strs;
int i;
strs = ft_calloc(sizeof(char *), (ft_strlen(to_split) + 1));
if (!strs)
return (NULL);
i = 0;
strs[0] = ft_calloc(sizeof(char), (ft_strlen(to_split) + 1));
if (!strs[0])
{
free(strs);
return (NULL);
}
if (get_strs(to_split, charset, &strs, &i))
{
i = -1;
while (strs[++i])
free(strs[i]);
free(strs);
return (NULL);
}
free_set_null(&strs, i);
return (strs);
}

23
utils/ft_str_is_empty.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_empty.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 16:12:46 by cchauvet #+# #+# */
/* Updated: 2023/02/16 16:13:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_str_is_empty(const char *str)
{
size_t i;
i = 0;
while (str[i] == ' ')
i++;
return (str[i] == '\0');
}

27
utils/ft_strnchr.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:06 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
ssize_t ft_strnchr(const char *str, char c)
{
size_t i;
i = 0;
while (str[i] != '\0')
{
if (str[i] == c)
return (i);
i++;
}
return (-1);
}

26
utils/ft_strncpy.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:16 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
size_t ft_strncpy(char *dst, const char *src, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
dst[i] = src[i];
i++;
}
return (i);
}

31
utils/ft_strreplace.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strreplace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:46:20 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:58:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) -\
(stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
ft_strncpy(out, str, start);
ft_strncpy(out + start, fill, ft_strlen(fill));
sum = start + ft_strlen(fill);
ft_strncpy(out + sum, str + stop, ft_strlen(str) - stop);
out[sum + ft_strlen(str) - stop] = '\0';
return (out);
}

30
utils/ft_strshift.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strshift.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:11:04 by cchauvet #+# #+# */
/* Updated: 2023/02/15 18:16:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
void ft_strshift(char *str, int shift)
{
ssize_t i;
if (shift > 0)
return ;
else
{
i = 0;
while (str[i - shift - 1] != '\0')
{
str[i] = str[i - shift];
i++;
}
}
}

36
utils/utils.h Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
/* Updated: 2023/04/11 16:55:16 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
# include <stdlib.h>
# include "../libftx/libftx.h"
# include "../data/data.h"
# include "../env/env.h"
size_t ft_strncpy(char *dst, const char *src, size_t n);
int ft_is_in_quote(const char *str, size_t n);
char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop);
ssize_t ft_strnchr(const char *str, char c);
char *ft_getstr(const char *str, size_t n);
int ft_str_is_empty(const char *str);
char **ft_split_charset_quoted(const char *s, const char *charset);
void ft_strshift(char *str, int shift);
char *ft_quote_remover(char *str);
int ft_atoi_check(const char *nptr);
char *ft_get_executable(t_data *data, const char *name);
void ft_closer(int fds[2]);
void ft_mega_closer(int fds1[2], int fds2[2]);
void ft_add_fd(int fds[2], int fd);
#endif