mirror of
https://github.com/reactos/reactos.git
synced 2024-08-26 21:28:48 +00:00
![]() Suppose the following FOR-loop command, to be run from the command-line (if using a batch file, double each percent '%' sign): FOR %l IN ("a,b,c,d,e" "f,g,h,i,j") DO ( FOR /F "delims=, tokens=1-3*" %a IN (%l) DO @echo %a-%b-%c-%d ) The outermost FOR-loop enumerates the two strings "a,b,c,d,e" and "f,g,h,i,j" (placed in %l), and parse each of these in turn, splitting them at each specified delimiter (here only one character) ',' and storing the results in consecutive tokens %a, %b, %c, %d, with the last token %d containing all the remaining string (non-split). The expected result is: a-b-c-d,e f-g-h-i,j However, due to the way the delimiters string specified by the "delims=" option is stored (no stack/heap duplication of the FOR-option substring, but reading from it directly), during the first run of the innermost FOR-loop, the option string "delims=, tokens=1-3*" was truncated to just after the ',' due to the erroneous "delims=" parsing, so that when this FOR-loop ran for a second time (to deal with the second string), the option string was already erroneously truncated, without the "tokens=..." part, so that the parsing results were not stored in the tokens and resulting in: a-b-c-d,e f-%b-%c-%d instead. The solution is to save where the "delims=" string needs to be cut, but wait until running the actual FOR-loop to terminate it (and saving the original character too), run the FOR-loop body, and then restore the original character where termination took place. This allows having the FOR-loop option string valid for the next execution of the FOR-loop. |
||
---|---|---|
.. | ||
cmd | ||
explorer | ||
filebrowser | ||
progman | ||
rshell | ||
CMakeLists.txt |