From 622fad8ee21d3be8cba07905b3688a8a24b760d4 Mon Sep 17 00:00:00 2001 From: callum Date: Mon, 16 Feb 2026 22:26:23 +0000 Subject: [PATCH 1/9] concept history with struct --- include/.history.h.swp | Bin 0 -> 12288 bytes include/history.h | 25 +++++ src/.history.c.swp | Bin 0 -> 20480 bytes src/.main.c.swp | Bin 0 -> 12288 bytes src/history.c | 207 +++++++++++++++++++++++++++++++++++++++++ src/main.c | 14 ++- 6 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 include/.history.h.swp create mode 100644 include/history.h create mode 100644 src/.history.c.swp create mode 100644 src/.main.c.swp create mode 100644 src/history.c diff --git a/include/.history.h.swp b/include/.history.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..0f4b38b9fd671e1c6a5afa81defaa241af9fc79f GIT binary patch literal 12288 zcmeI2L2J}N6vw9?3supR3i7mIKI?AA+>Wjc8=Lz9_hGU?WXde*B4 z?ZGdhpFj|*UqVkJ_$hpoWEYgO^x&oP0{;wo^WMBSzef%sv)g&xeFz)ND}t``LR>z4 zqj!E>6`$vYP%_KPJWR~KYQOd%)n>0Jnc|i`p^T?60nLqQ1^Y8TM1mvf9$F zE$!N*jmpXxqf{5(x@XJjaVxTo2{3^Z5h#7qUSANm=+z7Ui`TEg#S7af3S}oIzyz28 z6JP>NfC(@GCcp+4HPCtlK4&NSP()Qod~jm;wuOn?b60Vco%m;e)C0!)AjFaajO z1em}nBp_oUt}F=gmK6T~Prm%~P89v=EGS zmVru9?E%ezD-HM*VP86J%c2^k*VYtZlWL~P4$9_vh!9b$CB(kfF(eLg80MF%{Nb?* z$?4R%RTx8#IUU>v=_@l*^f*NWc%VJiAe~emsZc|Aq_5DzyHZW}3(BGNIIOKRcV2rI zAi>}mnq?|TO{EirGLC01q!Tc9TER^qe^8}!RN@qXw|{U6Oo(9E6{^yssCrfruGkQO znJG7`UQl8=Y4kMH$k}{E)yM*NF=Uv4T8uH#2H}3UU-chW!-?J~icw`KUFctEAGM+G V2l~{;1vyNbnWBt|e4;ZHzX5X45XJxi literal 0 HcmV?d00001 diff --git a/include/history.h b/include/history.h new file mode 100644 index 0000000..f38ea9e --- /dev/null +++ b/include/history.h @@ -0,0 +1,25 @@ +//history header file +//decleartion of all the methods + + +#define HIST_LEN 20 + +//Check if a history command prompt has been entered +int check_history(char* tokens[INPUT_LEN]); + +//if not history, add current command to the history and then execute +void history_add(char* tokens[INPUT_LEN]); + +//creates a new struct token +struct history create_struct(char* tokens[INPUT_LEN]); + +//free the malloced memory at the end when exit character entered +void free_hist(); + +/** +//this will check and run the various variations of the history command +//int return for error handling +int history_exe(char* tokens[INPUT_LEN]); +**/ + + diff --git a/src/.history.c.swp b/src/.history.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..3d1103cff4a7bfd376c9c337d75f82488be39e89 GIT binary patch literal 20480 zcmeI3TZ|-S6~_ygivxnV1eF*4b_ndu?(|$1NPuBi6E4}&WgzS>gpA`_)BW{y?Q~Z) zRnz`Q?{M4jjVMgISrHwVG@!MDH{z{fxa zQm_b4UKRw8f``F4c<$05cosYZLhv^5+cyQl3*blKQE)$40Q=fCX?d z_$Kcjd<1+LEQ71Sh2U>vLGUX03-~s84BQXy09S&Gz%~$oue>n`PJl(Q4_prZPVwRo z;P>ED;5fJw)W9T|0Iy#d1TTTdKp$KSwu6hn1>ijJ;srtQG zW_CUp8=IMla6p1G zlO?7V9-8i}ldPM>4e9B|lp$kFTUO9X8d0-PQ-+t_%UF&y12-~Sub%57 z%)#DD7UjL%8vhcCv2EM2!dA>kzE>1?d#*z$D`Qw)G^f4 zFihCws<|VI+hKpF?3e}dPsDpN#vbq5G>*6=r5VN!J)F>A6)O3)?*vq`b!C zG+}hpQFCN>Q5NsaPnpk6S7@&4hEr-UBDdf!a?P6)AJS#7nb^N@@X(P1w=bIAriB#vihG?&bB!r(I5Tkl5pHHtZ){9IjH$y+ z(8tuw+(#sLNE(4>JT+bWrC;`beYB4)HZgEPtKc}8FT2a+wQvAEObyc@d2{j z4pt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_!{7MmdM3Qu^6s!VRlC!=MGtXS2SoCOyM6 z{BJ*$s(jh%T-uiV{I@!dHAlOR{yI02ZrOLsoBDq}4YpryX>6me6rww2v{NpOjcu-q z=hQe`I%9L+;FPcbRAn}?qIq-F7bi=4d_^<5r7Q!?7ZuE738}ttq3Oniq&hP*tCo_b zJH;j7kjTlO?8JZ)kcY+vmgG}u6t1)_on#Q|o<2czMNM*zmb09W~-@(8_yb8EfNUGk20>Dg4EC@S3 z#Ma^ra+H#e6gFpOd<3aPb*Z(=wPGH0jKW=QAc|53gGg1{yV|bAidqdWg43|!3Qfgu z1HvknriWq(0Zj$KBOs19(62jw7ev%mf?B6 zAak$9eCzW33Km`AQG;^7J6$g(9cWkmrwGjLi1s(-;YoxUh*Xfjx6Z<()!G8)UJuDe zxyf3|!f^(o8Lk3Xr0_+C>hvPm$g_4l;;wF5-%wYi8yPM_l#>>_(}IALiKI80b;(m9 zC}fTNWH;{bfgdZCiA)_g9E|zYd_up~=7uZd=&#(UvC-pronv9t7N=M4Sp-;S@}o6o zlvT?BsHjmdR!CTj*flMrse^UpZ<5=#D-UWf892<=ANXoAr+aWL!f>V8% z)ig=Fcy8o&F>tOjzw_*Jdc@cjQsxDQ$-xG1+vfMoArSq{SE# zZ~w?pj#yQe;^7;G-ebPVGVs98Ffy{eO*e#Fl<3;YB;zq$;lKRxCW|jzvaC1=G*0lI z;0O$FZMBDJS(Fa>OKL%wpvD9-Pe6T)AeRR*K_{dJprvki#JgvLauBGE`lx^hv)Iw_ zLWXq{0y)_6brj3wblf~|4DuI^BTWTf|tS5;N##y zpzVB{>Z@X)VxVH6VxVH6VxVH6VxVH6VxVH6VxVH6V&IGnNMW*k3G381y5&7T|2BlC q_0(ZD*7T``7A1FSN`;LVC!_@6-*3{IU0Hl^rDKNSKlhp^fBp-Rqj?7a literal 0 HcmV?d00001 diff --git a/src/.main.c.swp b/src/.main.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..b4e6d5073760ada0dd059ba053869965db9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mcwWjY_*+L*HU^|OP41P=6=LWU+lQ!C= zqB<`6z(Iu(x!vfEy`FTC=b$7zt9Kw25?$`s zbD*)ye+R;@+eZ1Ux8Ig9KNpyh^GT=Oof_N@o}G1s(C2)z)VIJe3wnLrFF!d2CK^&RC zAeXb;vk21#xgxr<-GnNn!jhq%uxIF7S;4=r$*w-;Ez>!(UGu;^B z`(qEUdaGo=nzO;+I`ivnj^AS{luCL=qh~Mol3iG%$@j~r +#include +#include +#include + +//declaring a struct called history +//contains an integer for the number in history.. confused if this is the array accessor +//contains pointer to strings- which is the tokenized input (need to malloc and then point seperatley) +struct history { + int commandNo; //the command number to be referenced (like an identity) (starts from 1) + char *commands[INPUT_LEN]; //the command line, each part of this array points to a string (token) +}; + +//history commandNo start at 1 and continue indefinetly until the death of the program +//this is the integer that the user refers to when calling their command? +//is this what the user calls as the command number +int globalCommand = 1; + +//the current head of the struct... ie like an index counter +int head = 0; //for circular array implementation +int total = 0; + +//need to declare an array of structs, intially empty and of 20 poisitons +//history is an array of tokens, however these are stored locally +//each position in this array is it's own struct which relates to a command +struct history arrHistory[HIST_LEN]; + + +//This method will be called when the input has been tokenised +//it's goal is to check that a history prompt has been entered and then execute the command +int check_history(char* tokens[INPUT_LEN]){ + + //if no commands, then just return + //if they have entered an empty input, no need to check as invalid + if (!tokens[0]) { + return 1; + } + + //check the first token is !- first sign of a valid history command + if (tokens[0][0] == '!') { + //history doesn't take parameters- invalid history prompt + if (tokens[1]) { + printf("History doesn't take parameters!\n"); + return 1; + } + + //at this point, the command is at least valid whether history prompt or normal command line + //Finaly code extraction-from github + //check maths working with all conditions + int pos; + if (tokens[0][1] == '!') { // If !! entered + pos = head; + } else { + + //this code below generates either a positive integer or a negative, deependent on call + char num_s[4]; + strncpy(num_s, tokens[0] + 1, 3); + int num = atoi(num_s); + + + //checks id the integer entered is valid + //boundary checking + if (num < -total|| num > total || num < -HIST_LEN || num > HIST_LEN || + num == 0) { + printf("Invalid history number entered!"); // TODO: Improve this message + return 1; + } + + + //implementation...not circular yet + //need to make this implementation circular + //this maths isn't working for my array implementation + //boundary condition not working + if (num > 0) { + pos =(num - 1) % HIST_LEN; + } else { + pos = (HIST_LEN + head + num) % HIST_LEN; + } + } + + printf("pos check: %d\n", pos); + //at this point, if the command isn't a history prompt then it will have returned to main + //if it is a history prompt, then the maths above has worked out the value to call + //this can be placed into tokens and then passed back to main + + //at this point, we are ready to interpret the command after Finlay's mathematical expertise + // Subsitute history element into tokens input + //need to modify this for the tokens and struct + //this is making tokens[i] point the malloced strings in the corrosponding array + + //array is index 0, pos however starts from 1, so have to less one when accessing the array + for (int i = 0; arrHistory[pos].commands[i]; i++) { + tokens[i] = arrHistory[pos].commands[i]; + + } + + //at this point now, tokens conatins the executeable history command + //it will either contain the + return 0; + + } + //if we get here, the command line should be added to the array + history_add(tokens); + return 0; +} + +//This method is called when no history call has been made from the command line +void history_add(char* tokens[INPUT_LEN]) { + + //reset command number for current head + arrHistory[head].commandNo = 0; + + //if circular occurs then have to free the element leaving the array of structs + for (int i; arrHistory[head].commands[i]; i++) { + free(arrHistory[head].commands[i]); + arrHistory[head].commands[i] = NULL; + } + + + //need to create a strcut then add it to the correct position in the struct array + //returns a new struct which can then be added to the head of the array + //overwrites memory address of old struct with new struct + arrHistory[head] = create_struct(tokens); + + //current number- test + printf("Struct number: %d\n", arrHistory[head].commandNo); + + //incrementation- does the maths deal with total... ask Finaly + total++; + + //head- next available position... circular implementation + head = (head + 1) % HIST_LEN; + +} + +/** +//This method will execute if a ! has been entered as the first token +int history_exe(char* tokens[INPUT_LEN]) { + + //this method will create a struct, which can then be added to the array of history + struct create_struct(tokens); + + //need to copy local tokens as they are just pointers and will change + //repeat for all tokens, token pointer = 1 + + //want to create a new position in the struct array + //declare new struct, fill it, add it to the history array + //how to know what commandNumber this struct will get + struct history currentLine; + int pos = 0; + + //after this, we need to add the current command line to the array of struct + while (token) { + //while you have a token, save it locallay + //want to malloc space for the current token + commands[0] = malloc(str_copy) + } + + +} +**/ + +//this method will create a struct which will then be returned to be added to the array of structs +struct history create_struct(char* tokens[INPUT_LEN]) { + //want to create a new position in the struct array + //declare new struct, fill it, add it to the history array + //how to know what commandNumber this struct will get + //globalCommand is what the user will type in... it is incremented by 1 each time... + //it is what the user will type in to the command line + struct history currentLine; + currentLine.commandNo = globalCommand; + globalCommand++; + + + //after this, we need to add the current command line to the array of struct + //current format- array of pointers to strings + //malloc new space + //repeat until tokens hit null + for (int i = 0; tokens[i]; i++) { + //here, you will have a current token + currentLine.commands[i] = malloc((strlen(tokens[i]) + 1) * sizeof(char)); + strcpy(currentLine.commands[i], tokens[i]); + } + + //at this point we have a new struct, it has the correct global command number + //it has the correct array of string pointers as it's variable + return currentLine; + } + +//frees history when an exit command has been entered to the terminal +//gets access to the array as it's a global variable +void free_hist() { + for (int i = 0; i< HIST_LEN; i++) { + for (int j= 0; arrHistory[i].commands[j]; j++) { + free(arrHistory[i].commands[j]); + } + } +} + + + + + + + diff --git a/src/main.c b/src/main.c index cf1f79a..5c84ec4 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "../include/env.h" #include "../include/execute.h" #include "../include/input.h" +#include "../include/history.h" #include #include #include @@ -36,14 +37,20 @@ int main(void) { getcwd(cwd, 100); printf("New HOME: %s\n", cwd); + //ready for input char input_buffer[INPUT_LEN]; // Buffer for user input char *tokens[INPUT_LEN]; // Pointers to each token in buffer clear(tokens); // Clears data left over from previous run which causes errors while (get_input(input_buffer, tokens)) { - // print_tokens(tokens); // Uncomment for debugging - if (!check_builtin(tokens)) { - run(tokens); + // print_tokens(tokens); // Uncomment for debuggin + + //Step 1: Check command is a history one, token is array of pointers to strings, each element is a token + //if check_history returns 0 (false) then it has not been a history call and therefore add to history + if (!check_history(tokens)) { + if (!check_builtin(tokens)) { + run(tokens); + } } clear(tokens); @@ -54,4 +61,5 @@ int main(void) { setpath(saved_path); free(saved_path[1]); printf("Restored path: %s\n", getenv("PATH")); + free_hist(); } From 977161dbd42e38de34aa8b39b23c116de9cb0f60 Mon Sep 17 00:00:00 2001 From: callum Date: Mon, 16 Feb 2026 22:28:58 +0000 Subject: [PATCH 2/9] history edit --- include/.history.h.swp | Bin 12288 -> 0 bytes src/.history.c.swp | Bin 20480 -> 0 bytes src/.main.c.swp | Bin 12288 -> 0 bytes src/history.c | 27 --------------------------- 4 files changed, 27 deletions(-) delete mode 100644 include/.history.h.swp delete mode 100644 src/.history.c.swp delete mode 100644 src/.main.c.swp diff --git a/include/.history.h.swp b/include/.history.h.swp deleted file mode 100644 index 0f4b38b9fd671e1c6a5afa81defaa241af9fc79f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2L2J}N6vw9?3supR3i7mIKI?AA+>Wjc8=Lz9_hGU?WXde*B4 z?ZGdhpFj|*UqVkJ_$hpoWEYgO^x&oP0{;wo^WMBSzef%sv)g&xeFz)ND}t``LR>z4 zqj!E>6`$vYP%_KPJWR~KYQOd%)n>0Jnc|i`p^T?60nLqQ1^Y8TM1mvf9$F zE$!N*jmpXxqf{5(x@XJjaVxTo2{3^Z5h#7qUSANm=+z7Ui`TEg#S7af3S}oIzyz28 z6JP>NfC(@GCcp+4HPCtlK4&NSP()Qod~jm;wuOn?b60Vco%m;e)C0!)AjFaajO z1em}nBp_oUt}F=gmK6T~Prm%~P89v=EGS zmVru9?E%ezD-HM*VP86J%c2^k*VYtZlWL~P4$9_vh!9b$CB(kfF(eLg80MF%{Nb?* z$?4R%RTx8#IUU>v=_@l*^f*NWc%VJiAe~emsZc|Aq_5DzyHZW}3(BGNIIOKRcV2rI zAi>}mnq?|TO{EirGLC01q!Tc9TER^qe^8}!RN@qXw|{U6Oo(9E6{^yssCrfruGkQO znJG7`UQl8=Y4kMH$k}{E)yM*NF=Uv4T8uH#2H}3UU-chW!-?J~icw`KUFctEAGM+G V2l~{;1vyNbnWBt|e4;ZHzX5X45XJxi diff --git a/src/.history.c.swp b/src/.history.c.swp deleted file mode 100644 index 3d1103cff4a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(9cWkmrwGjLi1s(-;YoxUh*Xfjx6Z<()!G8)UJuDe zxyf3|!f^(o8Lk3Xr0_+C>hvPm$g_4l;;wF5-%wYi8yPM_l#>>_(}IALiKI80b;(m9 zC}fTNWH;{bfgdZCiA)_g9E|zYd_up~=7uZd=&#(UvC-pronv9t7N=M4Sp-;S@}o6o zlvT?BsHjmdR!CTj*flMrse^UpZ<5=#D-UWf892<=ANXoAr+aWL!f>V8% z)ig=Fcy8o&F>tOjzw_*Jdc@cjQsxDQ$-xG1+vfMoArSq{SE# zZ~w?pj#yQe;^7;G-ebPVGVs98Ffy{eO*e#Fl<3;YB;zq$;lKRxCW|jzvaC1=G*0lI z;0O$FZMBDJS(Fa>OKL%wpvD9-Pe6T)AeRR*K_{dJprvki#JgvLauBGE`lx^hv)Iw_ zLWXq{0y)_6brj3wblf~|4DuI^BTWTf|tS5;N##y zpzVB{>Z@X)VxVH6VxVH6VxVH6VxVH6VxVH6VxVH6V&IGnNMW*k3G381y5&7T|2BlC q_0(ZD*7T``7A1FSN`;LVC!_@6-*3{IU0Hl^rDKNSKlhp^fBp-Rqj?7a diff --git a/src/.main.c.swp b/src/.main.c.swp deleted file mode 100644 index b4e6d5073760ada0dd059ba053869965db9d4876..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHN&u<$=6rLhl2vB}r-~f6xsAX0PTfcOVEaG+W^aYGGY!{`>!RcKpVY57V>{ld zX~Qbcyu4?0P{iA*qkg!&b8J*EJN1Uk%Qko2)KW|>#ncoArd~H3uVfCQQZ}W4Qs7<` zh@)z8&sMezTTg_&SlC9-JUx3a49Zt2pcGIFC;`^)jIoQrA>j8%8EXT_ zfq!wX;7gzbECU|_XMjau7qA7`4E#C7*iB#+_zL(8I0GyKHJ}9i_Aq0g0+)a~@CvXS z`2Hcr-U9Xm&jAkt|De9Vfxm!XfS-XC;9KAe;A3DBcpVrAq#pO-e5#a{0!jg;!2hnm zSw>V1IIq}F7-_@fxNQWE7ge>w8$68sfLqisB6}Zg4^Mi95vuWsdrhq{eQ;)?Ff0Q^ zycQZwZdHWqiLp6p4tXSQb3M|m>vY)VhUa)SiW@99;7P9>hqgnZ(F(~3YDVO5!AFwi3Z6!$`yr7i6lN-so1LqY7VxrnGCr%Kv3)8^)>%6#m&k#oyom=+~T&O->{ z2dyqe*F)FglX7Gp6!0hxypTpos~T>|hbgkTM@~ex5t8ReG|zEwP&YsvoFl`tgkQj` z5SI)KcYfDH=A!H6h&O0#9~~Aclj+y%BFKR#T}SdgK7v39A?-n6w8*bg!^hn5AQYTo zgo&($Bg75UChqb&_o9?V2Bz|1I^={`QdPTUj}tm(Ju$Y3Lat=-`M6edJS4ebJ1!>; zYoX$JjX2WePl#Ks@*vAA92U~Sxp&e8ub6-2Xc>_~F0V%9H+g_%=+}`8Z#sS)5@t~h zgUn4M4tYpC2>c)ve6|tLjx^m9lT*{PGnJ!9rsl>;en3B+6G7IV>EuzGV3#AGbPo|Y z4#`qv-55O}>5D*J54d5qWJhX)vAbiY_ySEFKX&BSW-%8mxq2ZKe${{x8XFyzHf)cI z?bmtlraSIhcTXXe0O<*E&dKf2&7>@LWADaYzd=(WbM~EcbbuD8W{(~n!6s~Sxt+D) zvvM(H4+F;&wb#XBTUY<~5D$n2?xH>{LlWmcwWjY_*+L*HU^|OP41P=6=LWU+lQ!C= zqB<`6z(Iu(x!vfEy`FTC=b$7zt9Kw25?$`s zbD*)ye+R;@+eZ1Ux8Ig9KNpyh^GT=Oof_N@o}G1s(C2)z)VIJe3wnLrFF!d2CK^&RC zAeXb;vk21#xgxr<-GnNn!jhq%uxIF7S;4=r$*w-;Ez>!(UGu;^B z`(qEUdaGo=nzO;+I`ivnj^AS{luCL=qh~Mol3iG%$@j~r Date: Tue, 17 Feb 2026 12:42:38 +0000 Subject: [PATCH 3/9] changed to array from struct --- include/history.h | 10 +--- src/history.c | 136 +++++++++++++++------------------------------- 2 files changed, 45 insertions(+), 101 deletions(-) diff --git a/include/history.h b/include/history.h index f38ea9e..649cd39 100644 --- a/include/history.h +++ b/include/history.h @@ -2,7 +2,7 @@ //decleartion of all the methods -#define HIST_LEN 20 +#define HIST_LEN 4 //Check if a history command prompt has been entered int check_history(char* tokens[INPUT_LEN]); @@ -10,16 +10,8 @@ int check_history(char* tokens[INPUT_LEN]); //if not history, add current command to the history and then execute void history_add(char* tokens[INPUT_LEN]); -//creates a new struct token -struct history create_struct(char* tokens[INPUT_LEN]); - //free the malloced memory at the end when exit character entered void free_hist(); -/** -//this will check and run the various variations of the history command -//int return for error handling -int history_exe(char* tokens[INPUT_LEN]); -**/ diff --git a/src/history.c b/src/history.c index e63132a..d4816b8 100644 --- a/src/history.c +++ b/src/history.c @@ -5,28 +5,12 @@ #include #include -//declaring a struct called history -//contains an integer for the number in history.. confused if this is the array accessor -//contains pointer to strings- which is the tokenized input (need to malloc and then point seperatley) -struct history { - int commandNo; //the command number to be referenced (like an identity) (starts from 1) - char *commands[INPUT_LEN]; //the command line, each part of this array points to a string (token) -}; - -//history commandNo start at 1 and continue indefinetly until the death of the program -//this is the integer that the user refers to when calling their command? -//is this what the user calls as the command number -int globalCommand = 1; +//array that stores all our history +//2D array, each row represents a hist_len +char *history[HIST_LEN][INPUT_LEN]; //the command line, each part of this array points to a string (token) //the current head of the struct... ie like an index counter -int head = 0; //for circular array implementation -int total = 0; - -//need to declare an array of structs, intially empty and of 20 poisitons -//history is an array of tokens, however these are stored locally -//each position in this array is it's own struct which relates to a command -struct history arrHistory[HIST_LEN]; - +int head = 0; //This method will be called when the input has been tokenised //it's goal is to check that a history prompt has been entered and then execute the command @@ -47,11 +31,9 @@ int check_history(char* tokens[INPUT_LEN]){ } //at this point, the command is at least valid whether history prompt or normal command line - //Finaly code extraction-from github - //check maths working with all conditions int pos; if (tokens[0][1] == '!') { // If !! entered - pos = head; + pos = (HIST_LEN + head -1) % HIST_LEN; } else { //this code below generates either a positive integer or a negative, deependent on call @@ -60,44 +42,46 @@ int check_history(char* tokens[INPUT_LEN]){ int num = atoi(num_s); - //checks id the integer entered is valid //boundary checking - if (num < -total|| num > total || num < -HIST_LEN || num > HIST_LEN || - num == 0) { - printf("Invalid history number entered!"); // TODO: Improve this message + //need to include boundary checking for negative num as can't access negative index + if (num <= -HIST_LEN || num > HIST_LEN ||num == 0) { + printf("You can only call to the last 20 commands!\n"); // TODO: Improve this message return 1; } - - - //implementation...not circular yet - //need to make this implementation circular - //this maths isn't working for my array implementation - //boundary condition not working + + //calculate the correct position + //issue with this maths need to fix it to work circular + + //positie case if (num > 0) { - pos =(num - 1) % HIST_LEN; - } else { - pos = (HIST_LEN + head + num) % HIST_LEN; - } + pos =(num - 1) % HIST_LEN; + } + //negative case + else { + pos = (HIST_LEN + head + num-1) % HIST_LEN; + } } - printf("pos check: %d\n", pos); + printf("pos check: %d\n", pos); + //ensure that this position exists in the array + //this would cause an error + if (!(history[pos][0])) { + printf("History call does not exits!\n"); + return 1; + } + + //at this point, if the command isn't a history prompt then it will have returned to main //if it is a history prompt, then the maths above has worked out the value to call - //this can be placed into tokens and then passed back to main //at this point, we are ready to interpret the command after Finlay's mathematical expertise // Subsitute history element into tokens input - //need to modify this for the tokens and struct //this is making tokens[i] point the malloced strings in the corrosponding array - - //array is index 0, pos however starts from 1, so have to less one when accessing the array - for (int i = 0; arrHistory[pos].commands[i]; i++) { - tokens[i] = arrHistory[pos].commands[i]; - + for (int i = 0; history[pos][i]; i++) { + tokens[i] = history[pos][i]; } //at this point now, tokens conatins the executeable history command - //it will either contain the return 0; } @@ -109,65 +93,33 @@ int check_history(char* tokens[INPUT_LEN]){ //This method is called when no history call has been made from the command line void history_add(char* tokens[INPUT_LEN]) { - //reset command number for current head - arrHistory[head].commandNo = 0; - //if circular occurs then have to free the element leaving the array of structs - for (int i; arrHistory[head].commands[i]; i++) { - free(arrHistory[head].commands[i]); - arrHistory[head].commands[i] = NULL; + for (int i; history[head][i]; i++) { + free(history[head][i]); + history[head][i] = NULL; } - - //need to create a strcut then add it to the correct position in the struct array - //returns a new struct which can then be added to the head of the array - //overwrites memory address of old struct with new struct - arrHistory[head] = create_struct(tokens); - - //current number- test - printf("Struct number: %d\n", arrHistory[head].commandNo); - - //incrementation- does the maths deal with total... ask Finaly - total++; + //now we have freed position, need to add the current token input to history + //current format- array of pointers to strings + //malloc new space + //repeat until tokens hit null + for (int i = 0; tokens[i]; i++) { + //here, you will have a current token + history[head][i] = malloc((strlen(tokens[i]) + 1) * sizeof(char)); + strcpy(history[head][i], tokens[i]); + } //head- next available position... circular implementation head = (head + 1) % HIST_LEN; } -//this method will create a struct which will then be returned to be added to the array of structs -struct history create_struct(char* tokens[INPUT_LEN]) { - //want to create a new position in the struct array - //declare new struct, fill it, add it to the history array - //how to know what commandNumber this struct will get - //globalCommand is what the user will type in... it is incremented by 1 each time... - //it is what the user will type in to the command line - struct history currentLine; - currentLine.commandNo = globalCommand; - globalCommand++; - - - //after this, we need to add the current command line to the array of struct - //current format- array of pointers to strings - //malloc new space - //repeat until tokens hit null - for (int i = 0; tokens[i]; i++) { - //here, you will have a current token - currentLine.commands[i] = malloc((strlen(tokens[i]) + 1) * sizeof(char)); - strcpy(currentLine.commands[i], tokens[i]); - } - - //at this point we have a new struct, it has the correct global command number - //it has the correct array of string pointers as it's variable - return currentLine; - } - //frees history when an exit command has been entered to the terminal //gets access to the array as it's a global variable void free_hist() { for (int i = 0; i< HIST_LEN; i++) { - for (int j= 0; arrHistory[i].commands[j]; j++) { - free(arrHistory[i].commands[j]); + for (int j= 0; history[i][j]; j++) { + free(history[i][j]); } } } From 8af562777c5f2d3e84541631ad4de68645918ebb Mon Sep 17 00:00:00 2001 From: callum Date: Tue, 24 Feb 2026 10:52:32 +0000 Subject: [PATCH 4/9] history maths fixed and comments cleaned --- include/.history.h.swp | Bin 0 -> 12288 bytes include/history.h | 3 +++ src/.history.c.swp | Bin 0 -> 20480 bytes src/.main.c.swp | Bin 0 -> 12288 bytes src/history.c | 17 ++++++++++------- 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 include/.history.h.swp create mode 100644 src/.history.c.swp create mode 100644 src/.main.c.swp diff --git a/include/.history.h.swp b/include/.history.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..7fdca810571fb5cf7898ea3fa9d4f60de0276bb3 GIT binary patch literal 12288 zcmeI2zityj5XLvOD1d+(4NxQ??6X6PAVd`*#S%mTJ2VJco7=H&<-NVr-5Np@3OaZN zcnWv~q`(7EQ9#X8@ZG-@D2mcrnv*`Qc04=t%};i5@*WIcjGoei{!rn$qSUuXpX|?H zH`La9rDE;eBCS3+`)Trelf?S@o;JP7=GNe}6Gu&Av_0M!4x+J5bI0R^oogb!Cemv{ z*2ivPI7)08vf^z&Ijy3^gn$q@KY>+sA3wb+|Msn$bnWW?`HxDb5D)@FKnMr{As_^V zfDjM@OHUx=E9xDlxX?~=yfaJ%cVne{k+M^cngHeSmhL4QL1rpsIEs zl1B�U;m+gn$qb0zyCt2mv7=1eS@w>&zO;3+uzQy_>y$=b?(CIz%C1YQyv;o5UC}eeFoTaJuhMe`RR9$#hFxPdPqSdxeO>q}Ji*YpN6xYE?hdRtSUAN&w z8z@e6p<}e@8ns1R3sY^(dX;k*2IlO`m!sXi{mJynZoOW+4I-_RR)Pe@A|wGPEnuwZdUw`)?YsA` z?!9ZrO#)J>R9--Q2+P+lv+q?mPEH5>y)Fo5@AzVL{+YJ~&)yLPjWCXT z9VxiyU9+3oCc@BZQvTP9gKjd zk?|}LSw9Yz!G5p@>;&7vpW)*7;2d}Y+ym|gi(nF*e`OGS7u*Z(0e6GF;4iP>U2qq; z6>I@dkTm%Y_%?U|EP>m=tzZsZ4PGK~@(=KL@HcQDNI?Rw0nd?``2%9i z4xS-V^9WGxua#zMEJ_L$seNi{MiuFbPV)I^VMayQT{o^y^{dwFneOVaP`#vx;nd%jZptupmea7xi!4f( z@?fN1PtrBDrd2y!)vA?g-K1h36;YZ@&;dWG9ya-CYvtNDLZ~R|_6jL3?}eb%GbpzF zHQ&}@a{)n-`|$BYhh`{}_Q!_H$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lu4dZD z(g=H>5HRKmFUj!bXlW(tK0sSsi8|M!4u-f8^XCbdHz2tYb-#+b*Jb-I>f*BBSc3Wd z8sSo3wol}^s4iQwEVg^A5AEW$HNw7w3L|p6osYd4b&+SkB)cp3Arul_?bWldG3CDx zVd}O~KI`rGB+SkQX5?bj?W9wK%l@;oju84>j23$q7-pfTWgM2y%YhP|dkK5i>e2=) z1X3*C$S>?mvizHCgi9#rb`%RP^2y}TMGpCv?G?`P#N9+`YlN|nPzmD5`~|t3<=i5S z7v!?&N_G>fkP1tNUc%hat69Onr^&7!=R6_aK@Y@}3eQO@&y>d}NWM)@!&DA^{H8FR zw#o5$vd;{M?FM|t@%lMUh&R#2<4O;0&n1zb;kiMWJTY)%qJwy4)^-i2iSPqW7ms?g zWWAZO!Qj|)>uk1{GZjiDEuqnphkMB?tkGoq0@3uDVOMc6U{{I30 Co6`3H literal 0 HcmV?d00001 diff --git a/src/history.c b/src/history.c index d4816b8..deb8fe2 100644 --- a/src/history.c +++ b/src/history.c @@ -5,12 +5,10 @@ #include #include -//array that stores all our history -//2D array, each row represents a hist_len +//2D array, each row represents an input to the command line char *history[HIST_LEN][INPUT_LEN]; //the command line, each part of this array points to a string (token) +int head = 0; //next available spot in the array -//the current head of the struct... ie like an index counter -int head = 0; //This method will be called when the input has been tokenised //it's goal is to check that a history prompt has been entered and then execute the command @@ -54,7 +52,11 @@ int check_history(char* tokens[INPUT_LEN]){ //positie case if (num > 0) { - pos =(num - 1) % HIST_LEN; + //if overflow has occured + //error as when full first time then this causes issues + if (history[head][0]) { + pos = (head + num -1 ) % HIST_LEN; //TODO: Error with this line + } else pos = num-1; //no overflow } //negative case else { @@ -62,14 +64,14 @@ int check_history(char* tokens[INPUT_LEN]){ } } - printf("pos check: %d\n", pos); //ensure that this position exists in the array + //this would cause an error if (!(history[pos][0])) { printf("History call does not exits!\n"); return 1; } - + printf("POS IS: %d\n", pos); //at this point, if the command isn't a history prompt then it will have returned to main //if it is a history prompt, then the maths above has worked out the value to call @@ -120,6 +122,7 @@ void free_hist() { for (int i = 0; i< HIST_LEN; i++) { for (int j= 0; history[i][j]; j++) { free(history[i][j]); + history[i][j] = NULL; } } } From c1402a4dd1127684038a64610380b7ad62f3ea56 Mon Sep 17 00:00:00 2001 From: callum Date: Tue, 24 Feb 2026 11:12:35 +0000 Subject: [PATCH 5/9] small changes --- include/.history.h.swp | Bin 12288 -> 12288 bytes include/history.h | 2 +- src/.history.c.swp | Bin 20480 -> 20480 bytes src/history.c | 1 - 4 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/.history.h.swp b/include/.history.h.swp index 7fdca810571fb5cf7898ea3fa9d4f60de0276bb3..2dc02ee36efa3e48517e8dcd59f777ff06826fdf 100644 GIT binary patch delta 136 zcmZojXh;xCG6?hZRj|}EWB>vI28QL|YzV{#K&%hMdSJX+QQ$c5 RW+T1Hj7&xblaJ|J0RTNm92x)s delta 132 zcmZojXh;xCG6?hZRj|}EWB>vI28JWHb26{q-Y9mNdEx=q&F`4SWLS^$GBD^*=2Vb( z+QQGkuo;N!fH(+<1A&+uh#&AVFx&^?xj@_v#9ct_0mMc?YzV{#K&%hMdVHG|1y1m8 PHq@KU$Y?V8n7$PNE1(=l diff --git a/include/history.h b/include/history.h index 1fe5fab..bd8cc9f 100644 --- a/include/history.h +++ b/include/history.h @@ -2,7 +2,7 @@ //decleartion of all the methods -#define HIST_LEN 4 +#define HIST_LEN 20 //Check if a history command prompt has been entered int check_history(char* tokens[INPUT_LEN]); diff --git a/src/.history.c.swp b/src/.history.c.swp index ea14f7fed0aff3ba766a241df7d36fbba4bd6e97..a497c994870b42ba78e98dd43820cc147e9c90c2 100644 GIT binary patch delta 221 zcmWm8K?}hE00rPTt!!pBm&IHrMLDpwgWQ}nNu2xuH@Wx++*TatCbjql+RWQ7p+I%+puFQqPb92m}}yJe%fbKKi^-OiF;!WV4~bWqsbS>(}uzFsudQKp_6Z!@%$xi01%tHV{hy@hffyhEqU%42TZ{aSagX0C6@DX8^G} z5DNk^3lK8_F(VLf;9_8C0peyLHUwgBApXe7z;F$SF9Y!$!vb^ HE6D@^m(Vj^ diff --git a/src/history.c b/src/history.c index deb8fe2..922f1f5 100644 --- a/src/history.c +++ b/src/history.c @@ -71,7 +71,6 @@ int check_history(char* tokens[INPUT_LEN]){ printf("History call does not exits!\n"); return 1; } - printf("POS IS: %d\n", pos); //at this point, if the command isn't a history prompt then it will have returned to main //if it is a history prompt, then the maths above has worked out the value to call From ba287a23d781ab4f3df2dc6d2fc1fc262659e872 Mon Sep 17 00:00:00 2001 From: Finlay Robb <60317020+finlaysr@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:26:37 +0000 Subject: [PATCH 6/9] Included stdio since it was needed --- include/history.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/history.h b/include/history.h index c8d5acc..ae248e2 100644 --- a/include/history.h +++ b/include/history.h @@ -1,7 +1,8 @@ //history header file //decleartion of all the methods - +#inlcude #include "../include/input.h" + #define HIST_LEN 20 // Checks if the input was a history invocation, and insert appropriate item. @@ -21,4 +22,4 @@ void output_hist(FILE *stream); void load_hist(); // Save the history to the history file -void save_hist(); \ No newline at end of file +void save_hist(); From a92e8e5cc4d28f7044bab9457e831ffda012e32d Mon Sep 17 00:00:00 2001 From: Finlay Robb <60317020+finlaysr@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:28:52 +0000 Subject: [PATCH 7/9] Fixed typo in include --- include/history.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/history.h b/include/history.h index ae248e2..b381f16 100644 --- a/include/history.h +++ b/include/history.h @@ -1,6 +1,6 @@ //history header file //decleartion of all the methods -#inlcude +#include #include "../include/input.h" #define HIST_LEN 20 From cc3d6764ca549455e48d91fc3b804e5234e47e68 Mon Sep 17 00:00:00 2001 From: Finlay Robb <60317020+finlaysr@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:30:44 +0000 Subject: [PATCH 8/9] fixed function name --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 883c0f8..79da788 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,7 @@ int main(void) { while (check_alias(tokens)) { // insert all aliases } - if (!check_hist(tokens)) { + if (!check_history(tokens)) { if (!check_builtin(tokens)) { print_tokens(tokens); run(tokens); From 2a96029fd69c5f7e0f5cd6bac6b3081ae5ef6c49 Mon Sep 17 00:00:00 2001 From: Finlay Robb <60317020+finlaysr@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:33:34 +0000 Subject: [PATCH 9/9] fixed funcion name --- src/history.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/history.c b/src/history.c index 3f11480..ea06eb1 100644 --- a/src/history.c +++ b/src/history.c @@ -140,7 +140,7 @@ void load_hist() { if (hist_file) { // check that .hist_list exists while (fgets(buffer, INPUT_LEN, hist_file)) { tokenize(buffer + 4, tokens); // +4 to skip the number - add_hist(tokens); + history_add(tokens); clear(tokens); } fclose(hist_file);