2013-04-04 20:11:17 +00:00
|
|
|
|
General Overview of How Things Work
|
2006-02-16 23:23:37 +00:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2009-01-17 12:55:46 +00:00
|
|
|
|
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.
|
2013-04-04 20:11:17 +00:00
|
|
|
|
We pull in the launch directory as the initial dir and set that in _tchdir. We make a handle to the default console out using CreateFile.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
2013-04-04 20:26:36 +00:00
|
|
|
|
Then we call Initialize(). Here we need to load ntdll.dll if it isn't loaded (windows 9x machines).
|
2009-01-17 12:55:46 +00:00
|
|
|
|
We also setup some global 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.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
|
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 a global struct "bc" which is NULL when not processing a batch file)
|
2016-11-05 14:55:55 +00:00
|
|
|
|
and if there is it will pull a new line from that file. If not, then it will wait for input.
|
2009-01-17 12:55:46 +00:00
|
|
|
|
Currently there is some stuff for set /a in there, which might stay there or see if we can find a better spot.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
|
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.
|
2012-09-28 19:36:49 +00:00
|
|
|
|
Then we look for redirections using GetRedirection() which will remove any redirection symbols.
|
2009-01-17 12:55:46 +00:00
|
|
|
|
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.
|
2016-11-05 14:55:55 +00:00
|
|
|
|
personally i dont like this code and i tried to change it before but failed.
|
2009-01-17 12:55:46 +00:00
|
|
|
|
it is confusing to me and i dont understand why a lot of it is there but apparently it is needed.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
|
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.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
|
Execute will try to launch the file using createprocess and falls back on shellexecute.
|
2016-11-05 14:55:55 +00:00
|
|
|
|
It calls a function called SearchForExecutable() to find the full path name and looks in all the correct locations like PATH,
|
|
|
|
|
current folder, windows folder. If it cant find it, just fails and prints out a message.
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
|
|
Some useful functions that are used a lot:
|
2009-01-17 12:55:46 +00:00
|
|
|
|
|
2013-04-04 20:26:36 +00:00
|
|
|
|
split() - splits a string into an array of string on spaces that aren't inside quotes. which you need to call freep() on later t clean up.
|
2016-11-05 14:55:55 +00:00
|
|
|
|
//Split it<69>s used to take the Arguments from Command Line, it<69>s the best option for almost all the cases.
|
2009-01-17 12:55:46 +00:00
|
|
|
|
//If the Command has special needs as Dir, it<69>s better to make a Parser INSIDE that Command(as DIR has)
|
|
|
|
|
//Dont get mad(as i did): Split() can be find in Misc.c file.Really easy to follow.
|
2016-11-05 14:55:55 +00:00
|
|
|
|
//Also remember split() receives the Command Line, but the Command Line WITHOUT command name.
|
2009-01-17 12:55:46 +00:00
|
|
|
|
|
|
|
|
|
splitspace()-split a string into an array of string using spaces as splitters.which you need to call freep() on later to clean up.
|
|
|
|
|
//This is the son of split() for commands that manage in the same way "/" and "\" when are INSIDE the paths.
|
|
|
|
|
//i.e move works in the same way with: move C:\this/is\a/mess C:\i/know,and with move C:/this/is/a/mess C:/i/know
|
|
|
|
|
//Other commands DOESNT.
|
|
|
|
|
//You can find also in misc.c
|
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
|
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
|