‫Hello and welcome, everybody, in this lecture.
‫We're going to implement some standard functions in the library, so things like string, Leane, string
‫copy, you know, some of the things we created in the kernel, we're going to put into the standard
‫library, then use the programs will use.
‫We're also going to be implemented string talk, which is incredibly important stock that function that
‫will allow us to tokenized strings, essentially, OK, we can cut strings and split them.
‫OK, and this is very important because when we end up implementing process arguments, we're going
‫to need to parse them from the shelf.
‫OK, because you're going in the shell, you're going to put a filename along with a couple arguments
‫for the program, OK?
‫And we are going to want to be able to cut those up so that we can pass the arguments to the program.
‫OK, your competency programers, you know what I'm talking about.
‫So let's say you made a program called Test.
‫If I went test A.B.C. testing, we know that AAG of one would have ABC agreed to would have testing
‫and Arvizu you would have test.
‫So we're going to implement that.
‫OK, we eventually.
‫So yeah, that's a brief explanation of the string talk function that we will also be implementing in
‫this lecture.
‫It's responsible for just splitting the strings, essentially.
‫I'm sure some of you have heard of it.
‫OK, so we're going to start this by creating a string dot C file in the study lab and also a string
‫dot file in the lab.
‫So we're going to go hash tag if and death Peko as String Hajjaj to find Peatross String Hajjaj hash
‫tag and if ok, perfect.
‫So inside string that C just include string dot org.
‫Now we've written a lot of this.
‫It doesn't make sense for us to write it all again.
‫Just go to string dot C in your kernel in the string directory and we're going to copy and paste everything
‫from here because there's no point in writing all of that again when we've already done it right.
‫So just copy and paste that into the lab.
‫Now, the reason we're not calling the kernel for these simple operations is because it's a waste of
‫cycles and the kernel commands should be restricted to only serious things, things that can't be done.
‫And New Zealand, OK, all of this string copy stuff that can easily be done in a standard library,
‫there's no need for that to be done in kernel land for user programs.
‫It makes sense for use the land on Connellan to have their own separate versions of this of these functions
‫essentially.
‫OK, so OK, so we've done that copy and paste them again into the header file of string dot C.
‫OK, so we've got them in the source file now, paste them in the header file and just remove all the
‫function body so we're left with prototypes only.
‫OK, you guys all know how to do that.
‫If you've already done it, you might want to skip ahead to when I finish doing this and as a matter
‫of fact, I'll pause the video and come back once I've removed all the bodies of excellence.
‫Once you've done that, you should have a bunch of prototypes and in string that say you should have
‫all of the code and the bodies.
‫OK, so that's excellent.
‫So now just up here, just include the boards of Hajj.
‫OK, another resolve, this little dependency on line 14 four is digit.
‫OK, perfect.
‫So we have functions for copy and strings for getting string length and so on.
‫So that's all good news.
‫We now need to create the string talk function.
‫So go to String Dot C and we're just going to go char espie equals.
‫Now this is a global variable and we're going to go char string talk char string and I'll tell you what,
‫make this equal to zero because otherwise we might have to include a header.
‫Father just said it's zero, it's the same thing.
‫And we're going to go Khanjar to a turns telemeters and I was just going to go in.
‫It equals zero and Atlantico string delimiters and for a full specification of this function, just
‫look it up guys.
‫It's in the standard library string talk.
‫It just tokenized the string.
‫OK, so here we're going to say if the string is null or the global variable ASP is now, then return
‫null and we can just return zero there instead.
‫Same thing.
‫And I were going to say if string or ASP is no or false, I should say S.P. whole string.
‫OK, so that's if we have a valid string provided to us and our global string is now then set our global
‫string to the string that was just provided.
‫That's what we're saying there.
‫So when I was going to say chop start equals ESP while one four I equals zero I below lenni plus plus
‫if asked Crispi starts.
‫So we're basically pulling out the character that that piece starts pointing to equals the dilemma to
‫this character I.
‫Peace start plus plus break, so all we're doing there is we're looping through all the telemeters,
‫OK, and we're checking if the character we're currently on in string is equal to that delimiter.
‫OK, that's what we're doing there.
‫OK, guys.
‫So now by here, we're going to say if I is equal to land speed, Quispe, start, break, OK?
‫And now if askaris esp is equal to char no.
‫Then speak with zero return S.P..
‫So now we want to find the end of the substring, so find end of substring, we do this by going, wow,
‫ask Quispe does not equal No.
‫Four equals zero i blokland i plus plus if askers esp equals telemeters I then ask Chris asp equals
‫char zero break.
‫So now we're just going to say aspy plus plus if I below Lenn then break.
‫I know this is confusing guys, but you're going to have to go through this step by step if you want
‫to understand that there's really no need for you to understand how this function works.
‫It's not part of OS development, so I won't really explain it further.
‫But if you did want to understand all of this code, just go through it in the debugger and you'll understand
‫what's going on.
‫But there really is no need to know this for kernel development.
‫We just need this standard function that comes prepackaged in every compiler anyway.
‫But all of C because we're doing OS dev, we have to write our own.
‫So here we're going to go return P start.
‫OK, just like that.
‫We've just implemented string talk now and the thing about string torque is it relies on this global
‫variable.
‫OK, now that means you have to be careful how you use this function.
‫OK, and it's certainly not multi threading safe.
‫If you ever did want to use this in a multithreaded environment.
‫So just copy and paste this prototype and we're going to put it in the header file for String Dot and
‫we now have string talk.
‫OK, so let's just go to memory dot see inside of the kernel and we're just going to copy and paste
‫everything in here and we're going to do the same thing basically for the memory functions.
‫So just go to your standard library and we're going to create a new file called Memory Dot, see in
‫the standard library.
‫And we're just going to paste that in.
‫OK, just like that.
‫OK, and we're going to create a new file called Memory Dot as well.
‫And we're going to go hash tag if and death peatross memory H.
‫Hash tag and hash tag define features memory H so we can see if you've copied and pasted the whole far
‫from the kernel.
‫We're already included memory dot.
‫So all we're now going to do is we're going to copy and paste all of the prototypes in here and we're
‫going to remove them just like before so that we're left with a bunch of prototypes.
‫So what I'll do is I'll pause the video and come back when I've done that so we can see that I have
‫now taken the function bodies away so that we have the prototypes set up correctly.
‫These directly map the ones in memory that c remove this include memory w.h.
‫That was also copy and paste it in for the header file because obviously we don't want that.
‫We can see SIST is a dependency, so we're going to have to include assisted death dot org.
‫OK, and that will resolve that dependency right there.
‫So we've got memory dot C and string dot C so we need to go to the Makefile now and add those in.
‫So copy and paste STD biog.
‫Oh down here.
‫And we're going to change that to string dotto string dot C string dot C String Dotto.
‫And here we're going to go build String Dotto and just copy and paste that again and we're going to
‫do the same from memory.
‫Dotto So memory dotto memory dot c memory dot C memory dot of OK and again just put that at the back
‫here.
‫Build memory.
‫Dotto So that is for the object file requirements at the top here.
‫So now just go make clean build that S.H..
‫And we can see that Kampala's absolutely fine.
‫Excellent, so when I was just going to have a quick test to string talk so you can see how it works,
‫because I want you to be completely aware of that for me.
‫Implement the program argument so that you understand how it's working completely.
‫OK, so what we're going to do then we're going to go to Planktos Tazi and we're going to include String
‫Dot.
‫OK, and we're going to define a string of words.
‫So we're going to go const char words equals hello, how are you.
‫OK, uh, that that's perfectly fine.
‫And I we're going to go const Shotokan equals string talk words and the dilemma is spacebar.
‫OK, so now we're going to go while Tolkan and we're going to go Tolkan equals string talk now, OK.
‫And we're going to put a space bar there.
‫So that's how the string token works.
‫So we start by specifying the pointer to the string and then if we're still working with the same string
‫we just passed now here and then keep the dilemma to the same.
‫So that's how that works.
‫OK, guys, and if we now go print token, uh, well, in fact you print F, I should say print F and
‫we're going to go oh percent s and then we're going to do the new line and then we're just going to
‫go token so you guys know what that does.
‫And before I forget, guys, this should be a char and it shouldn't be a pointer either.
‫It should instead be an array on the stack.
‫So just do that, OK?
‫Because that ensures we can write to it then because we want to be able to write to this memory.
‫OK, so just go make clean build that S.H..
‫And perfect now just because she'd been kumu.
‫And we're going to type in blankets and we see hello, new line, how new line, our new line, you
‫new line.
‫So you can see this screen talk function allows us to easily split the strings.
‫And we're going to be taking advantage of this functionality to make process arguments so that we can
‫pass things to Agfa, OK, of the process that we start.
‫So, yeah, that's perfect.
‫That works really well.
‫Thanks for watching.
‫And your Col's now in a state where we can continue and begin creating program arguments.
‫Congratulations.