‫Hello, everybody.
‫What if I was to go echo hello?
‫Well, Echo is a program hello is the message we want to print.
‫So as I'm sure you're all aware, Agfa and AAG see in the main function of any C program, accept arguments
‫past to the program.
‫We know AIG-FP zero is the file name is being run of one.
‫Is the first argument passed the program.
‫We know that that's how it works.
‫Our colonel doesn't support that yet.
‫Wouldn't it be great for us to implement something like that so that you can go echo hello and say hello,
‫I put it to you or something like that?
‫Right.
‫Well, we can implement IG SCENOGRAPHY and it starts with parsing these commands, the commands.
‫We're passing the show.
‫We need to split them, OK?
‫We need to split them and create a bunch of command arguments and pass that to the colonel, OK?
‫And then it will be able to inject those into our process when our process starts and then we'll be
‫able to extract the arguments.
‫So we're going to start this by going to start Hadash in the lab.
‫We're now going to go struct command document
‫char argument 512 struct command document next.
‫So as you can see, this is a linked list.
‫OK, so each command argument part will be able to have five, 10, 12 bytes.
‫So in our case of echo test, echo will be in the first argument.
‫Tests will be in the second argument.
‫OK, and it's a linked list.
‫OK, so go to Peter Stazi and we're going to start writing some code for this now.
‫So we're just going to go struct command document process, pause command, const command and Chemex.
‫OK, so this will parse the given command echo test into different command arguments.
‫OK, so we go struct command argument route command equals zero char s command one thousand twenty four.
‫So the maximum command size can be 1024 bytes.
‫If the maximum is above the size of s command then will return an error because they're telling us that
‫they allow their command documents to be bigger than the maximum and we're not going to allow that.
‫So we return zero here.
‫Otherwise we're going to copy the string straight into the command, OK?
‫And we're going to need to include strings on the Hajj as well, guys.
‫OK, just like that, unless you've resolved string and copy and now we're going to go Shotokan equals
‫string token as command.
‫Space, so we're splitting by spaces in the buffer.
‫OK, so we're going to say if the token is now, then there was an error and go to out and hour down
‫here, we're going to have out and we're just going to return route command.
‫OK, now, if we manage to parse the first argument correctly, then we're going to create the route
‫commands.
‫So we just go route command equals S Mallak size of command document.
‫OK, and then we're going to say if the command failed to be created, go to out, there was a problem.
‫Otherwise, we're going to copy into the commands argument, the token we parsed.
‫OK, well, I'm going to set the next variable on route command to now, because we know that there's
‫no more in the linked list right now.
‫So this code here is the first argument in the command they provided when I was going to go strike command
‫argument.
‫Current equals rule.
‫Command token equals string token.
‫Now we're going to pass in the space there, while Tolkan does not equal zero strike command argument,
‫new command equals Peatross mallock size of struct root, not an abstract command document.
‫Now, if the new command we fail to create, then we'll go through it again, or as a matter of fact,
‫we can break cleanly to break in this case, and then we're going to copy into the new command argument,
‫the token we just passed.
‫And the maximum count will be the size of the new command argument when I was going to go to new command.
‫Next equals now.
‫And we're going to go current.
‫Next equals new command.
‫So here we are just in the linked list now.
‫Current equals new command.
‫And I'm finally we're going to go Tolkan equals String Tok No Space, which I'll get the next token
‫ready for a ready for us to loop back around.
‫OK, so that should be it for parsing space isn't a command argument.
‫So let me explain what's going on.
‫We come in here, we copy the command they provided to us here into our command buffer.
‫Why do we do this?
‫Because String Token modifies the buffer and we can modify Khanjar.
‫OK, we'll damage that string and we don't want to do that.
‫And plus we won't be able to do that because the memories read-only so we copy that into the local buffer
‫on the stack here and then we have something we can damage and mess with safely.
‫OK, so then we we basically.
‫Find the first token, OK, and if we found the first choking successfully, then we basically go through
‫command Eco's picturesque Mallak, which creates room for the command, the very first command.
‫We then copy that past Tolkien into the command.
‫OK, now we check if there's any more to come, any more to parse.
‫And if there is, then we create a new command.
‫Again, we copy that Newtok and we parsed into the new command argument.
‫OK, and then we added to the link list.
‫OK, and then we loop back around until string talk returns now.
‫And when that happens, we're done parsing.
‫Finally we return the command, so that'll give us a list of commands.
‫OK, so we're going to test this now and see if everything works.
‫OK, so copy and paste PTW Pass Command and we're going to put it in the header file here, OK?
‫And then we're going to head over to Planktos.
‫See, we're going to get rid of this mallock stuff we done.
‫We don't need that anymore and we're just going to go char string equals hello world just like that.
‫OK, and we're going to say parse command string and the maximum will be the size of string.
‫OK, I'm going to go struct command argument will command equals that and then just do an if statement
‫of command so it doesn't complain that we're not using the variable.
‫OK, and as a matter of fact, we don't have to do that.
‫We can just go print F percent.
‫S New Line will command.
‫And let's take a look, a command argument, we can see that it's called arguments, OK?
‫That's the the variable names.
‫So we can give a command argument, whereas the file blank to see there are command arguments, OK?
‫That'll give me the first the first part of that.
‫OK, now I can copy and paste that here and I can go through command next argument which will give us
‫the next part of it.
‫Now there's one more thing I noticed.
‫Guys go to Pitstop.
‫Hey, I've misspelled I've misspelled command document, so just change the structure and spell it correctly.
‫Command argument.
‫OK, I was a bit of a typo there and I'm going to go make clean build that S.H. I can see to that Kampala's
‫perfectly fine.
‫I'm going to uh now run the emulator.
‫OK, we can see that, we can see how Shell is loaded.
‫I'm now going to do blank to death and I can see hello and then a new line and then world so we can
‫see that the command provided hello world has been split into different parts.
‫So we have the command argument and we also have the the next part of that command, OK, which is Walt.
‫OK, so we can see that that works nice and easily and it's quite nice.
‫It works.
‫So that concludes part one of passing arguments to the process.
‫You can see that we've now parsed those strings correctly into different command arguments.
‫So in the next coming lectures will pass these command arguments to the colonel, which will then inject
‫them into the process that we're trying to start.
‫But it'll take some time before we can get to that point.
‫So thanks for watching part one.