Added a more technical readme for people that want to understand cmd.

svn path=/trunk/; revision=18401
This commit is contained in:
Brandon Turner 2005-10-10 18:57:56 +00:00
parent 7a0a97076f
commit 657a7f0496
2 changed files with 23 additions and 2 deletions

View file

@ -1 +1,19 @@
Nothing yet...
General Overview of How THings Work
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First it comes into _main in cmd.c(1811). The command line params are taking in and if it is unicode it uses CommandLineToArgvW. This can cause a problem on older machines and that is why we have our own custom _CommandLineToArgvW to help this along. We pull in the launch directory as the inital dir and set that in _tchdir. We make a handle to the default console out using CreateFile.
Then we call Initialize(). Here we need to load ntdll.dll if it isnt loaded(windows 9x machines). We also setup some gloabl vars like default io handles and nErrorLevel and set %prompt% to $P$G. This is where all command lines switches given to cmd on startup are done.
From here main calls ProcessInput(). This is where cmd loops for getting input and doing the commands. First it checks to see if there is a batch file(note: there is agolbal struct "bc" which is NULL when not processing a batch file) and if there is it will pull a new line from that file. If not, thne it will wait for input. Currently there is some stuff for set /a in there, which might stay there or see if we can find a better spot.
Once there is input taken in from the command line it is sent into ParseCommandLine(). In here we fist check for aliases and convert if need be. THen we look for redirections using GetRedirection() which will remove any redirection symbols. and pass back info about where to redirect. from this info it will do some switching around with the handles for where things go and send them as need be. personally i dont like this code and i tried to chnage it before but failed. it is confusing to me and i dont understand why a lot of it is there but apparently it is needed.
It sends the new string without any redirection info into DoCommand(). In this function we just look to see what should be done. There is one of 2 things that could happen. 1) we fnd the matching command and send it off to that commands little section. 2) we dont find it so we send it to Execute() and see if it is a file that we can do something.
Execute will try to launch the file using createprocess and falls back on shellexecute. It calls a function called SearchForExecuteable() to find the full path name and looks in all the correct locations like PATH, curreent folder, windows folder. If it cant find it, just fails and prints out a message.
Some useful functions that are used a lot:
split() - splits a string into an array of string on spaces that arent inside quotes. which you need to call freep() on later t clean up.
IsValidPathName(), IsExistingFile(), IsExistingDirectory() - all do what you would expect.
PagePrompt() - ask them to hit a key to continue
FilePromptYN[A]() - ask them a yes or no question

View file

@ -33,4 +33,7 @@ A lot of commands on failure just spit out GetLastError instead of looking for t
We need more batch files like the one Royce made for "set /a". What out for if bugs when doing this... could lead to in the wrong direction when looking for a regression.
*Remove dependance on __REACTOS__
__REACTOS__ = 0 doesnt compile and is useless. __REACTOS__ = 1 has been the default and works just fine on windows.
__REACTOS__ = 0 doesnt compile and is useless. __REACTOS__ = 1 has been the default and works just fine on windows.
*Add Breaker
THere is partly code in place for this already. However it is broken and not finished. PocketCMD which is open source and based off ros cmd does do this correctly though. So there is something to look at and see how it can be done. though it is hard to find where they are doing it even though they are based on eachother they look pretty different now a days.