From 657a7f049649e808f33f19e05dd73abe6f8bc0be Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Mon, 10 Oct 2005 18:57:56 +0000 Subject: [PATCH] Added a more technical readme for people that want to understand cmd. svn path=/trunk/; revision=18401 --- reactos/subsys/system/cmd/readme2.txt | 20 +++++++++++++++++++- reactos/subsys/system/cmd/todo.txt | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/reactos/subsys/system/cmd/readme2.txt b/reactos/subsys/system/cmd/readme2.txt index 0b42c941a5b..b349b7b8e15 100644 --- a/reactos/subsys/system/cmd/readme2.txt +++ b/reactos/subsys/system/cmd/readme2.txt @@ -1 +1,19 @@ -Nothing yet... \ No newline at end of file +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 diff --git a/reactos/subsys/system/cmd/todo.txt b/reactos/subsys/system/cmd/todo.txt index 153855b2e71..47ab11ca856 100644 --- a/reactos/subsys/system/cmd/todo.txt +++ b/reactos/subsys/system/cmd/todo.txt @@ -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. \ No newline at end of file +__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. \ No newline at end of file