From 766b5d4d6ae55d0f08d9a0d10dc1e477ebd4e224 Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 01:41:07 +0100 Subject: [PATCH 1/6] fix betty --- linkedlist.c | 84 ++++++++++++++++++++++++++++++++++++--------------- main.c | 1 + main.h | 1 + shell | Bin 17552 -> 0 bytes 4 files changed, 62 insertions(+), 24 deletions(-) delete mode 100755 shell diff --git a/linkedlist.c b/linkedlist.c index b63b765..5c6618a 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -3,78 +3,114 @@ envstruct *insert_end(envstruct *head, char *key, char *value) { envstruct *new_node = malloc(sizeof(envstruct)); - - if (new_node == NULL) { - return NULL; + + if (new_node == NULL) + { + return (NULL); } new_node->key = strdup(key); new_node->value = strdup(value); new_node->next = NULL; - if (head == NULL) { - return new_node; + if (head == NULL) + { + return (new_node); } envstruct *curr = head; - while (curr->next != NULL) { + + while (curr->next != NULL) + { curr = curr->next; } curr->next = new_node; - return head; + return (head); } +/** + * get_value - gets value of env var + * @head: head variable + * @key: value variable + * + * Return: NULL +*/ char *get_value(envstruct *head, char *key) { envstruct *curr = head; - - if (head == NULL || key == NULL) { - return NULL; + + if (head == NULL || key == NULL) + { + return (NULL); } - while (curr != NULL) { - if (strcmp(curr->key, key) == 0) { - return curr->value; + while (curr != NULL) + { + if (strcmp(curr->key, key) == 0) + { + return (curr->value); } curr = curr->next; } - return NULL; + return (NULL); } +/** + * remove_value - remove env variable + * @head: head variable + * @key: key variable + * + * Return: 0 or 1 +*/ int remove_value(envstruct **head, char *key) { - if (head == NULL || *head == NULL) { - return 1; + if (head == NULL || *head == NULL) + { + return (1); } envstruct *curr = *head; envstruct *prev = NULL; - while (curr != NULL) { - if (strcmp(curr->key, key) == 0) { - if (prev == NULL) { + while (curr != NULL) + { + if (strcmp(curr->key, key) == 0) + { + if (prev == NULL) + { *head = curr->next; - } else { + } + else + { prev->next = curr->next; } free(curr->key); free(curr->value); free(curr); - return 0; + return (0); } prev = curr; curr = curr->next; } - return 1; + return (1); } -void free_list(envstruct *head) { - while (head != NULL) { +/** + * free_list - frees the list_mem + * @head: head variable + * + * Return: void +*/ +void free_list(envstruct *head) +{ + while (head != NULL) + { envstruct *temp = head; + head = head->next; free(temp->key); free(temp->value); diff --git a/main.c b/main.c index fe8ceff..6d4384b 100644 --- a/main.c +++ b/main.c @@ -119,6 +119,7 @@ int is_builtin_cmd(char *cmd) /** * exec_builtin_cmd - execute builtin commands * @argv: argument vector - points to arguments entered + * @head: head of lists. * * Return: void */ diff --git a/main.h b/main.h index 3721755..39022a0 100644 --- a/main.h +++ b/main.h @@ -25,6 +25,7 @@ typedef struct env_var char *value; struct env_var *next; } envstruct; + extern char **environ; char *lineptr; diff --git a/shell b/shell deleted file mode 100755 index 9e81928790f98b7e458921e7baab08fb97d77f93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17552 zcmeHPe{@t;e!mkKjR+ z=clUX-SjDK$CTw(djT>=3CK^2_UZmHwcAl{25(mSgF1gqx!-Gb|Jjb*kzIMUvMXQU zr2P~S3RBJ}<%Is`X@727Lq;e}-FD5|&P|snGr^SFptAZ@I{M#fuU^~L1f(0`rn?j@ zm~wmf!jAItpDjGht8{x_<4~^q%~YpX%xa0Rn>%M#OSHNr-j>-^y=mUu>bY}*sYGzL z41wYb;E(3ivb!4u#;uz$9?r7uif4Z$8?WW0-!SXry7zwibn{nMGz9*x{P@0c-}rD6 z=}_EcLpoH*pPphCe?4lXL;0u?&x&pl!j&k*4fvz-de-0d7w>&%!?DTDvdn}nuNZrN=xJLENM5M7XmP(0uDw0lb7EQ546LjDiU()vdKjli0wYV$0$88<6L%>bjmi75;)Lk4;qo~|3-UIcV<%C+ z4WGnLKnHDjz=reuCEqvLaGt+}PqE>Z+Rx>{=$hv;!G@PH2pX{Ae2*jXbQ?~6=2BzB zsSPgkY&hqRWFZ?)*D4pohL2(pwBCkaX~XZg;iGN%S{sguVU=bZewBp^(Qd;lZ1^S{ zK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^qSSlc2cbWBG31SY|5y9UHj+rQ=I29 zTEEhzKM^?1w}QTb%Y8xknWFJJeWTus`9bAN5?6Km=X?)*r3b#&1K;d{=REMez-hjP zLMj@bZ!bvwN-gGhkrjNz!ZlE z#RPzlE5p+s-{plp$@=r!uV`end+PWDgHqL}*+M!CP5)hARE?u>7W!Mbgy~H$yJ`i9odEoAa zE9(|Ric?8u*w9MGl2yW7w&I>e3s;!;EM2-fyvAI!aM6mesZT6~`1}AJ6`*qs4nUt& zaA2Q1C}Bx)@ZdKcHlULh?VBxaYLHG-H~@9@!3CM?GVzvlyv=NEjjE#+4h8x}M2h5r z4u{B$MI-5mkXe^!GhD9d=!Vn4btJqJKH1a@SaEI7@BD=Musm6Ydl9PXTFg`6U~ z6yKsDQK9e7Z0~grm-YF6$^2ZGJ>4&< zFrBJc>l3#fN1^XI_V)RE7Sn)3o4&I+%U8hS=fecY&-)Wh=V^7`pK!+?ft>ax*gmi0 zXKHAkVx&B?J?|sLfsqQ^^L_|Z-v5A#Eabyp9sxsp3vAE(2~3x2WsaZqm~Mld_9~d? z{R*ZbZSRg>!y<TE ze`_ZnY{&FPmpwm+Go7Nxfo!R;o#KR`x0dYv=kIS!c^{DV-T8Y%+w=H~fY#J>mS&l_ z?caic+GqQkfYM~TOR?6c+x{I$?Dj_jN|osZcC0<{{L!p9g$f;i(3h#T&%x*C-TKTk zJqz0ko4vKKQVkG=^%OV6GkysIn!DUS?`!bChrs{t0bPGo*pA2Xd%&pwY|s0jgE$~T zh4wS-h3%PM2D#l{gtT^zqTCMqU_0hV!&6r z9fe}0VyCVlmhzBx7|@Bk4k+zSas0gg(&fRiOGEv!_BK^n<(hEZF6+|eTFU Date: Wed, 26 Jul 2023 02:47:34 +0100 Subject: [PATCH 2/6] implement the cd built-in function and fix the global variable issue --- linkedlist.c | 3 ++- main.c | 19 +++++++++++++++++-- main.h | 4 ++-- shell | Bin 0 -> 22144 bytes 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100755 shell diff --git a/linkedlist.c b/linkedlist.c index 5c6618a..0778e6c 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -18,7 +18,8 @@ envstruct *insert_end(envstruct *head, char *key, char *value) return (new_node); } - envstruct *curr = head; + envstruct *curr; + curr = head; while (curr->next != NULL) { diff --git a/main.c b/main.c index 6d4384b..2f7a06c 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,8 @@ #include "main.h" int main(void); +char *lineptr; + /** * main - Entrance to program * @@ -146,7 +148,10 @@ void exec_builtin_cmd(char **argv, envstruct *head) } if (strstr(argv[0], "cd") == argv[0]) { - /** cd_cmd(argv); */ + if (cd_cmd(argv) == -1) + { + perror(""); + } } } @@ -283,8 +288,18 @@ void unsetenv_cmd(char **argv, envstruct *head) * * Return: void */ -void cd_cmd(char **argv) +int cd_cmd(char **argv) { + int stat; + + stat = chdir(argv[1]); + + if (stat == -1) + { + perror(""); + return (-1); + } + return (0); } diff --git a/main.h b/main.h index 39022a0..f41e0c8 100644 --- a/main.h +++ b/main.h @@ -27,14 +27,14 @@ typedef struct env_var } envstruct; extern char **environ; -char *lineptr; +extern char *lineptr; void exit_cmd(int); void env_cmd(void); void setenv_cmd(char **argv, envstruct *head); void unsetenv_cmd(char **argv, envstruct *head); -/** void cd_cmd(char **argv); */ +int cd_cmd(char **argv); void exec_builtin_cmd(char **argv, envstruct *head); void exec_executable_cmd(char *cmd, char **argv, char **env); diff --git a/shell b/shell new file mode 100755 index 0000000000000000000000000000000000000000..98ade317161ae03fc8fdf8ea893ce8f5236d9da1 GIT binary patch literal 22144 zcmeHP33OCdn!XhXASx-4D4-1`i%Tm-f{2I$#ZvH?ArLW9?ACr1sY+6kq%yT&P*K_v zkLfaPy4$^N4=zX1wp+$V8y6(F5U?4Ij$@v}E%YV1{rQ%B2 zo>xDV$?H~Brk71?h_9JBV_HLWYD2s!(=xSX*379hX9QD;;B@Yp;tJr8#?+GK)eQaC zL73{!qK$%A{zyhsisYnUwQRw&`(n4Yblf?r?xt7DXR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>hJ|vq|8A_@i4;9_&vJXgmMY~-c zuIv=e4wWv||cE2{Q~mA*TFFG+jV|LXmjqBOqk#clsD5Yit>l%C)$Ug6(DKx0?6ulB9f`Il<^(fp&L>{LJg5*X!A*{gl=uDPU*x67{aqwEzO z0=eDZ+#d*Wb91~4&T3!r^qm*-rP>cvO1qGtvjj0;17=NBM#}cfT)00ZfKyyJ#Y)9a z)z}dd@j5FcXtTUfdRs|TLtVF8e~tpCViy+Tb&DqGA=iLY?J8Z`cJ9yqfeN89&Sl_Y G*?$7>dtRyl literal 0 HcmV?d00001 From 7c84497926bf7e7c709534699e39751c2a333a3b Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 03:02:16 +0100 Subject: [PATCH 3/6] fix whole code for full compilation --- linkedlist.c | 9 ++++----- main.c | 9 ++++++--- shell | Bin 22144 -> 22144 bytes 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/linkedlist.c b/linkedlist.c index 0778e6c..5d560d6 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -2,6 +2,7 @@ envstruct *insert_end(envstruct *head, char *key, char *value) { + envstruct *curr = head; envstruct *new_node = malloc(sizeof(envstruct)); if (new_node == NULL) @@ -18,8 +19,6 @@ envstruct *insert_end(envstruct *head, char *key, char *value) return (new_node); } - envstruct *curr; - curr = head; while (curr->next != NULL) { @@ -67,14 +66,14 @@ char *get_value(envstruct *head, char *key) */ int remove_value(envstruct **head, char *key) { + envstruct *curr = *head; + envstruct *prev = NULL; + if (head == NULL || *head == NULL) { return (1); } - envstruct *curr = *head; - envstruct *prev = NULL; - while (curr != NULL) { if (strcmp(curr->key, key) == 0) diff --git a/main.c b/main.c index 2f7a06c..010eae7 100644 --- a/main.c +++ b/main.c @@ -10,9 +10,10 @@ char *lineptr; */ int main(void) { + envstruct *head = NULL; + atexit(clean_up); signal(SIGINT, sig_int_handler); - envstruct *head = NULL; while (1) { @@ -235,7 +236,9 @@ void env_cmd(void) */ void init_env_list(envstruct *head) { - while (*environ != NULL) + int i = 0; + + while (environ[i] != NULL) { char *key = strtok(*environ, "="), *val = NULL; @@ -246,7 +249,7 @@ void init_env_list(envstruct *head) } head = insert_end(head, key, val); - *environ++; + i++; } } diff --git a/shell b/shell index 98ade317161ae03fc8fdf8ea893ce8f5236d9da1..eb43a924a9b3db1395ef9c9d2910311699afe937 100755 GIT binary patch delta 2493 zcmZ8ieNa?Y6n_uc6k1q9z7}>_KtrVoTr|+ivhc~%vX2=lZE75ow5F_ahE+=m#*Jon z9xKSPMn`LMG98<&CY>TvK`maEAB;7M=^u;@`e>mjt(IcA{my+$Mmw|j+AjV@p;>xJ8*I;3 z6vgt62!T^n57tGMz_>Q>l*mia>Cr=`)hwmQaE$7qRFH1wzD###23WR zVM*DX@yy*gdd7YY9n4(jO}9Bw-LN$hM$gcQ(#)*e>&?cmhlPL>MGrg5lRzMPgK5~Y zP#!zm;~=$G18O!N8dWwN4Kr=!br1k^^e-VAJ8InrSsP$2o5h{&oP~7<fU%y5U&I zxNyc4DZfLevxdV8HFm(b9z4uM2|Nkahhi>@0M`v$4p&*^&Mr*(Hp_MZ`wCd|v)8Ki zbToU?go#pMT2BMjE~RZ0&7N96QqGRKXPt;Izk=bWwU}*(PBf3Zg-~Ga9JNonG`jt8kCiu1?-Lo{)^{XpMeb`mIyozt&;xrlg#b2fxeUD6}rP zJY{dYvF)_CJ=h+zw-&Y?_I5B*Y-lI-t-7)3t1h@{i_O;y^jc17!tkF$(B`}>I-Qf~ zoFNf1$YlC4$FDw58M*n+i|OoCvOl8xatoZF++b{^7jp}8S}_nXjTz)zU%er&V)6WM z$A}-iA$FpUddR+3fX+G=$d_hN|3P4aQ4w$jJCs1^&XGwZ~|_%6BB})Z(2q4zQ zKsq&2-f2(z$F>IMry75Lka*T@6|;>o*1&ZbF&rz{L1RbYuzs)9U5Ezp%XONQzlPGl zQFl=5=P>Vru2J1THWPlQ76~C*s3p%!v-0jwTM1Nzd$Q*i4%xI0Q#h|Gtr+!}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ctcs(&#Zrr^2A_M+U7I9vai1mdW0` zvZr&t?5%1fo7FP6%`7r?wjr&{I@=ERg3jIs+pM!H*e0Fr3caK_ugE)PW#Pp(B-9u= zgXOfvn#+3VxHT)zp+U6@V(GTkF@7~tK%-jGpirzngeGnLxGp%!K687LNJO(ZLeo<- zR6HFrSm33Hbbh4c;=u>xu#nQZw5 zMbTOdx-jrAsbW)$^PZ$uKS8?APES=QcUfSuD`L_9xPM|3XtT{`JUIyU#NiO(Vh7YL zI%rF?t$f5eoUjnvD$>Ou2K5i(GTpXW*-`4XrH;y)BuPqHpS=8M`TU>J7^>(4oQ#FJ z$Jxg)ONk28vfUXNmKxkGPL^W$aiSoiVTTe$+FHY|!vsSNZZWTWU)WYBpuF4M|_RGK->y%;!gv3?k?w>QR^PiFF`;4i}SOfH$iWK)~TF_LH7qaPr;p? z*TMM|(E1SPZ-Z{`OgK45ELS@?V!uZ;n<&cR3z(+H+>RSG;DCxfw&<c>#6v z8LAWV)8v?FXOHRiiK(oP-Usg?AJ$=1k98jXgtd?EL)$|!lkAxe6ox1Jxu{Lg{0%|@ zH)zfzI~z;oSXYo2tB($04NxoAbri(9mtykl?CXY{yle5yNIkO)60}0#^*VZ(D48Uc zW)&@Er)XbMZp;vTSH$lQ{a!S~Vo%q16*`fYAgHi-lN`mRmPKj0SW6M?)`<21Z7a@Y z7CK+NfpySSXB~=db>=dn9_LcFlNOcaT6$A-+a%;5euvOz;kktNm5gAWbgJY=6icJe TOFv{+C`PVh`3<||d&B+*9ANV+ From 90ab2dafbad445b8d258096370499065f03c5fd0 Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 03:16:15 +0100 Subject: [PATCH 4/6] initialize lineptr with NULL --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 010eae7..4eeb0b7 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,7 @@ #include "main.h" int main(void); -char *lineptr; +char *lineptr = NULL; /** * main - Entrance to program From 4aa30f7ca4a9484d7dd2309256a2f072e057da3d Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 03:31:07 +0100 Subject: [PATCH 5/6] add a return statement to env_cmd --- main.c | 1 + shell | Bin 22144 -> 22144 bytes 2 files changed, 1 insertion(+) diff --git a/main.c b/main.c index 4eeb0b7..fd2a55e 100644 --- a/main.c +++ b/main.c @@ -228,6 +228,7 @@ void env_cmd(void) printf("%s\n", environ[i]); i++; } + return; } /** diff --git a/shell b/shell index eb43a924a9b3db1395ef9c9d2910311699afe937..00ea9a38a9f69cf7680215cc013a9223662473b1 100755 GIT binary patch delta 1020 zcmYLIZAepL6n@{CndUy6A7Sd|0x>ba%|$2?dABQ+NGKNNpTMkN_Cre|F&YM!IaJ<+ zgrEo#`ymxe=+iACr&baau}G+>aKoi5m#tXbo_F_F7w$Rl`<&-I=iGC)vlH~}1ijgl zka6R;kS<28!);~dhlIw{o}{b3G50{i$8^K?6hcJF7Z~B*mAKd4w@JH>4l`HIPCCbC za;oSGi{&&>k=b(h(+6xc_a1A`v-HhWg6~91=9rNyyyhY=zss^H2~p7}gbAJ{D-NAcZ>Q!$|od*Ir9?E@wo-L#jM^Vg0aT6FDpb`u^V;7X1d7imb$)!;5njlcQ!~Tb&C2VFl7uIQD5-Jev#!@@I}kA9DzRvpOHYwQ}}B5f)!bAh7Uog z3%(XA7vPV$D=Oa7yjCtP=nUsId$j8{jj2f+2+0NX2}3MlMO9|{hBd&Ju;Z{tnFKq? zuEWlE*nfN*!ByKlM0n)7Fga*5FF$y(me!VwVojrODIpLa3S&R)b22;TbQ6 zWlbc1-!BQh&rpO^ZxvoBwfp}h!J84u+TRp-#$#wpR;p7+UtPMbMS&;4HD$)D%&6xiH8f3$DM{4ivhjO#!sRYH1`TG8 zMa|$?JBMROOtEQv5IH|6rVnF#yja*Qh}H`B39`6dS(kyf%-QDpnZ zTQ%ZU-tZ@$K$J1V0PW9Awe)_Kho*$2@;r5CIxH6r1}BVrq1%~Rl>swWJo5cgyqFxV#O*8&8u|N@~nmY6P0GIYpsUP6BdnW5H%(k?$^N? z-y4TMT|;-Ltvp+DubL24yZ@^^6E>}7R^F~DD1ae!&CsDV z&W~R#)7N9?kC*f5myx%+Hu$XB?-DkCo)F@C6k|6gg?I+c{UXE+&;v}4W^5Q(2wXBH z#5Uk0d>Vl3U~(F`$LDsx<{8z}SxK-RkJ@CJ8?`xp-h9R!pg!OX^C+jl#a~f5Vjk^9 ztRoGvi>@L*pdrM18biE9v4t+)>&q#evZiG_r6*$z2C!Y2%Fb+TC%H??(za(9^st%j sGP75G-6h2wf6O5zpP!{)il0x>tPx# From e0ec559d5998b75685d75ab581a10646aac9bbfd Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 03:59:01 +0100 Subject: [PATCH 6/6] remove return statement from env_cmd --- main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/main.c b/main.c index fd2a55e..4eeb0b7 100644 --- a/main.c +++ b/main.c @@ -228,7 +228,6 @@ void env_cmd(void) printf("%s\n", environ[i]); i++; } - return; } /**