Page 1 of 1

Optimizations related to Performance

Posted: 18 May 2011 14:44
by Ed Dyreen
I am trying to make my batch faster, It takes 2days, 6hours on a PIV 2000g 500MB laptop

So I discovered a technique that that enables a script to execute functions without having to jump to this function using call nor goto. This proved to be fast, no that's a joke REALLY FAST

Code: Select all

SpeedOfMacro = SpeedOfFuncting / [b]REALLY[/b]

:function
goto eof


I started using for tokens to detemine the functions parameters, do something with it (SIMPLE things like get filename and store the variable )

Then I introducent the concept of Objects

The idea is that I request an Object to be created let's say Object.HOST

I wan't this object to be a Extension so one of the tokens will be Extension the token is called Object.Extension.

Based upon Object.Extension I try to call a macro that returns me the Object.Extension

It is expected that I can create any kind of Object that way Object.Drive Object.RegAdd etc..

Code: Select all

echo.
echo.
echo.FullPath.LocalHost.SCRIPT=!FullPath.LocalHost.SCRIPT!_
echo.
::
echo.Post.define: 'Create.Object' [OK]
for %%? in (  Create.Object ) do set "%%~?=set "Object.Name=%%~b" &set "Object.Extension=%%~c" &set "Object.Data=%%~d" &set "Error.Binary=%%~e" &echo. &echo.Object.Name:^^^!Object.Name^^^!_ &echo.Object.Extension:^^^!Object.Extension^^^!_ &echo.Object.Data:^^^!Object.Data^^^!_ &echo.Error.Binary:^^^!Error.Binary^^^!_ &echo. &echo.call Create.^^^!Object.Extension^^^!"
echo.Pre.define: 'Create.Object' [OK]
echo.

::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Object.Name"   ¦"Object.Extension"   ¦"Object.Data"         ¦"Error.Binary"'    ) do %Create.Object% %(>nul)%
  for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Host"¦"FileName"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) do %Create.Object% %(>nul)%


echo.endoftest
pause
exit

::testin
set "%%~?=
 set "Object.Name=%%~b"
 &set "Object.Extension=%%~c"
 &set "Object.Data=%%~d"
 &set "Error.Binary=%%~e"
 &echo.
 &echo.Object.Name:^^^!Object.Name^^^!_
 &echo.Object.Extension:^^^!Object.Extension^^^!_
 &echo.Object.Data:^^^!Object.Data^^^!_
 &echo.Error.Binary:^^^!Error.Binary^^^!_
 &echo.
 &echo.call Create.^^^!Object.Extension^^^!
"


by the way these are some other macros, they are already debugged and fully operation, ow yes you need to delete %err.set.this% "" and some other variables:

Code: Select all

            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"StoreVAR"' ) do %ERR.Get.RegRead.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"StoreVAR"' ) do %ERR.Get.RegRead.TokenVAR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"StoreVAR"' ) do %ERR.Chk_empty.RegRead.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"StoreVAR"' ) do %ERR.Chk_empty.RegRead.TokenVAR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"StoreVAR"' ) do %ERR.Chk_exist.RegRead.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"StoreVAR"' ) do %ERR.Chk_exist.RegRead.TokenVAR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"StoreVAR"' ) do %ERR.Chk_deep.RegRead.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-3 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"StoreVAR"' ) do %ERR.Chk_deep.RegRead.TokenVAR% %(>nul)%
            ::
            for %%? in ( ERR.Get.RegRead.TokenSTR ) do       set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! equ 0                                  for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!"                               ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Get.RegRead.TokenVAR ) do       set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! equ 0                                  for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!"                              ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_empty.RegRead.TokenSTR ) do    set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! equ 0                                  for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!" ^&for %%^^^! in ( "%%~d" ) do !ERR.Chk.IsDefined.TokenSTR! %()% ^>nul    ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_empty.RegRead.TokenVAR ) do    set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! equ 0                                  for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!" ^&for %%^^^! in ( "%%~d" ) do !ERR.Chk.IsDefined.TokenSTR! %()% ^>nul    ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_exist.RegRead.TokenSTR ) do    set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! neq 0 ( %ERR.Set.THIS% "Reg query '^^^!FullPathKey^^^!' /v '^^^!KeyName^^^!'" ) else    for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!"                               ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_exist.RegRead.TokenVAR ) do    set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! neq 0 ( %ERR.Set.THIS% "Reg query '^^^!FullPathKey^^^!' /v '^^^!KeyName^^^!'" ) else    for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!"                              ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_deep.RegRead.TokenSTR ) do    set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! neq 0 ( %ERR.Set.THIS% "Reg query '^^^!FullPathKey^^^!' /v '^^^!KeyName^^^!'" ) else    for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!" ^&for %%^^^! in ( "%%~d" ) do !ERR.Chk.IsDefined.TokenSTR! %()% ^>nul    ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk_deep.RegRead.TokenVAR ) do    set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!" ^&^&set /a ERR = 0 ^|^|set /a ERR = 1 ^&( if ^^^!ERR^^^! neq 0 ( %ERR.Set.THIS% "Reg query '^^^!FullPathKey^^^!' /v '^^^!KeyName^^^!'" ) else    for /f "skip=4 tokens=3* delims=   " %%§ in ( '2^^^>nul reg query "^^^!FullPathKey^^^!" /v "^^^!KeyName^^^!"' ) do set "Content=%%§" ^&set "%%~d=^^^!Content^^^!" ^&for %%^^^! in ( "%%~d" ) do !ERR.Chk.IsDefined.TokenSTR! %()% ^>nul    ) ^&( echo. ^&echo. ^&echo. RegRead    : '%%~d' ^&echo. FullPathKey: '^^^!FullPathKey^^^!' ^&echo. KeyName    : '^^^!KeyName^^^!' ^&set /p "?= Content    : '^^^!Content^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else set /p "?= [OK]" ^<nul ) "

            ::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"RegTypeSTR"¦"ContentSTR"' ) do %ERR.Get.RegWrite.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"RegTypeVAR"¦"ContentSTR"' ) do %ERR.Get.RegWrite.TokenVAR% %(>nul)%
            ::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"¦"RegTypeSTR"¦"ContentSTR"' ) do %ERR.Chk.RegWrite.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"¦"RegTypeVAR"¦"ContentSTR"' ) do %ERR.Chk.RegWrite.TokenVAR% %(>nul)%
            ::
            for %%? in ( ERR.Get.RegWrite.TokenSTR ) do        set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&set "RegType=%%~d"       ^&set "Content=%%~e" ^&( if defined Content set "Content=^^^!Content:""=\"^^^!^^^" ) ^&^>nul reg add "^!FullPathKey^!" /v "^!KeyName^!" /t ^^^!RegType^^^! /f /d "^!Content^!" ^&set /a ERR = ^^^!ErrorLevel^^^!                                                 ^&( echo. ^&echo. ^&echo. reg add: '^^^!FullPathKey^^^!' ^&echo. KeyName: '^^^!KeyName^^^!' RegType: '^^^!RegType^^^!' ^&set /p "?= Content: '^!Content^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^!ERR^!]" ^<nul ) else    set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Get.RegWrite.TokenVAR ) do        set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&set "RegType=^^^!%%~d^^^!"    ^&set "Content=%%~e" ^&( if defined Content set "Content=^^^!Content:""=\"^^^!^^^" ) ^&^>nul reg add "^!FullPathKey^!" /v "^!KeyName^!" /t ^^^!RegType^^^! /f /d "^!Content^!" ^&set /a ERR = ^^^!ErrorLevel^^^!                                                 ^&( echo. ^&echo. ^&echo. reg add: '^^^!FullPathKey^^^!' ^&echo. KeyName: '^^^!KeyName^^^!' RegType: '^^^!RegType^^^!' ^&set /p "?= Content: '^!Content^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^!ERR^!]" ^<nul ) else    set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk.RegWrite.TokenSTR ) do       set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&set "RegType=%%~d"       ^&set "Content=%%~e" ^&( if defined Content set "Content=^^^!Content:""=\"^^^!^^^" ) ^&^>nul reg add "^!FullPathKey^!" /v "^!KeyName^!" /t ^^^!RegType^^^! /f /d "^!Content^!" ^&set /a ERR = ^^^!ErrorLevel^^^! ^&( if ^^^!ERR^^^! neq 0 %ERR.Set.THIS% "reg add '^!FullPathKey^!' /v '^!KeyName^!' /t '^!RegType^!' /d '^!Content^!'" )    ^&( echo. ^&echo. ^&echo. reg add: '^^^!FullPathKey^^^!' ^&echo. KeyName: '^^^!KeyName^^^!' RegType: '^^^!RegType^^^!' ^&set /p "?= Content: '^!Content^!'" ^<nul ^&                           set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk.RegWrite.TokenVAR ) do        set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&set "RegType=^^^!%%~d^^^!"    ^&set "Content=%%~e" ^&( if defined Content set "Content=^^^!Content:""=\"^^^!^^^" ) ^&^>nul reg add "^!FullPathKey^!" /v "^!KeyName^!" /t ^^^!RegType^^^! /f /d "^!Content^!" ^&set /a ERR = ^^^!ErrorLevel^^^! ^&( if ^^^!ERR^^^! neq 0 %ERR.Set.THIS% "reg add '^!FullPathKey^!' /v '^!KeyName^!' /t '^!RegType^!' /d '^!Content^!'" )    ^&( echo. ^&echo. ^&echo. reg add: '^^^!FullPathKey^^^!' ^&echo. KeyName: '^^^!KeyName^^^!' RegType: '^^^!RegType^^^!' ^&set /p "?= Content: '^!Content^!'" ^<nul ^&                            set /p "?= [OK]" ^<nul ) "

            ::for /f "usebackq tokens=1-2 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"' ) do %ERR.Get.RegDelete.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-2 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"' ) do %ERR.Get.RegDelete.TokenVAR% %(>nul)%
            ::for /f "usebackq tokens=1-2 delims=¦" %%b in ( '"FullPathKeySTR"¦"KeyNameSTR"' ) do %ERR.Chk.RegDelete.TokenSTR% %(>nul)%
            ::for /f "usebackq tokens=1-2 delims=¦" %%b in ( '"FullPathKeyVAR"¦"KeyNameVAR"' ) do %ERR.Chk.RegDelete.TokenVAR% %(>nul)%
            ::
            for %%? in ( ERR.Get.RegDelete.TokenSTR ) do       set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&( if defined KeyName set "KeyName=/v "^^^!KeyName^^^!"" ) ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" ^^^!KeyName^^^! ^&^&set /a ERR = 1 ^|^|set /a ERR = 0 ^&( if ^^^!ERR^^^! neq 0 ^>nul reg delete "^^^!FullPathKey^^^!" ^^^!KeyName^^^! /f ^&set /a ERR = ^^^!ErrorLevel^^^! )                                       ^&( echo. ^&echo. ^&echo. reg delete: '^^^!FullPathKey^^^!' ^&set /p "?= KeyName   : '^^^!KeyName^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else    set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Get.RegDelete.TokenVAR ) do       set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&( if defined KeyName set "KeyName=/v "^^^!KeyName^^^!"" ) ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" ^^^!KeyName^^^! ^&^&set /a ERR = 1 ^|^|set /a ERR = 0 ^&( if ^^^!ERR^^^! neq 0 ^>nul reg delete "^^^!FullPathKey^^^!" ^^^!KeyName^^^! /f ^&set /a ERR = ^^^!ErrorLevel^^^! )                                       ^&( echo. ^&echo. ^&echo. reg delete: '^^^!FullPathKey^^^!' ^&set /p "?= KeyName   : '^^^!KeyName^^^!'" ^<nul ^&if ^^^!ERR^^^! neq 0 ( set /p "?= [ERROR:^^^!ERR^^^!]" ^<nul ) else    set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk.RegDelete.TokenSTR ) do       set "%%~?=set "FullPathKey=%%~b"       ^&set "KeyName=%%~c"       ^&( if defined KeyName set "KeyName=/v "^^^!KeyName^^^!"" ) ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" ^^^!KeyName^^^! ^&^&set /a ERR = 1 ^|^|set /a ERR = 0 ^&( if ^^^!ERR^^^! neq 0 ^>nul reg delete "^^^!FullPathKey^^^!" ^^^!KeyName^^^! /f ^&set /a ERR = ^^^!ErrorLevel^^^! )   ^&( if ^^^!ERR^^^! neq 0 %ERR.Set.THIS% "reg delete '^^^!FullPathKey^^^!' '^^^!KeyName^^^!'" )    ^&( echo. ^&echo. ^&echo. reg delete: '^^^!FullPathKey^^^!' ^&set /p "?= KeyName   : '^^^!KeyName^^^!'" ^<nul ^&                           set /p "?= [OK]" ^<nul ) "
            for %%? in ( ERR.Chk.RegDelete.TokenVAR ) do       set "%%~?=set "FullPathKey=^^^!%%~b^^^!"    ^&set "KeyName=^^^!%%~c^^^!"    ^&( if defined KeyName set "KeyName=/v "^^^!KeyName^^^!"" ) ^&^>nul 2^>^&1 reg query "^^^!FullPathKey^^^!" ^^^!KeyName^^^! ^&^&set /a ERR = 1 ^|^|set /a ERR = 0 ^&( if ^^^!ERR^^^! neq 0 ^>nul reg delete "^^^!FullPathKey^^^!" ^^^!KeyName^^^! /f ^&set /a ERR = ^^^!ErrorLevel^^^! )   ^&( if ^^^!ERR^^^! neq 0 %ERR.Set.THIS% "reg delete '^^^!FullPathKey^^^!' '^^^!KeyName^^^!'" )    ^&( echo. ^&echo. ^&echo. reg delete: '^^^!FullPathKey^^^!' ^&set /p "?= KeyName   : '^^^!KeyName^^^!'" ^<nul ^&                           set /p "?= [OK]" ^<nul ) "



In the end I would like to be able to call a lot of functions this way, I think setlocal ena is the only thing you need to test these macros, I am tired and well, they are much faster than any goto :label ()

This is a lot of code, paste it in notepad because the forum could use improvement |code]|/code]
Arrowbar suggested on code view :idea:

Re: Optimizations related to Performance

Posted: 18 May 2011 18:41
by Ed Dyreen
I am stuck :?

Code: Select all

echo.
echo.
echo.FullPath.LocalHost.SCRIPT=!FullPath.LocalHost.SCRIPT!_
echo.
::
echo.Post.define: 'Create.Object' [OK]
for %%? in (  Create.Object ) do set "%%~?=set "Object.Name=%%~b" &set "Object.Extension=%%~c" &set "Object.Data=%%~d" &set "Error.bool=%%~e" &echo. &echo.Object.Name:^^^!Object.Name^^^!_ &echo.Object.Extension:^^^!Object.Extension^^^!_ &echo.Object.Data:^^^!Object.Data^^^!_ &echo.Error.bool:^^^!Error.bool^^^!_ &echo. &set "Create.Object.Extension=%%Create.^^^!Object.Extension^^^!%%" &echo.for /f "usebackq tokens=1-2 delims=¦" %%f in ( '"^^^!Object.Data^^^!"¦"^^^!Object.Name^^^!"' ) do call ^^^!Create.Object.Extension^^^! &for /f "usebackq tokens=1-2 delims=¦" %%f in ( '"^^^!Object.Data^^^!"¦"^^^!Object.Name^^^!"' ) do call ^^^!Create.Object.Extension^^^!"
echo.Pre.define: 'Create.Object' [OK]

echo.Post.define: 'Create.FileName' [OK]
for %%? in (  Create.FileName ) do set "%%~?=echo.b=y%%f%%o_"

echo.Pre.define: 'Create.FileName' [OK]

set /p "?=Pre Execution Create.Object [OK]" <nul
::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Object.Name"   ¦"Object.Extension"   ¦"Object.Data"         ¦"Error.bool"'    ) do %Create.Object% %(>nul)%
  for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Host"¦"FileName"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) do %Create.Object% %(>nul)%
echo.Post Execution Create.Object [OK]

echo.endoftest
pause
exit



set "%%~?=
 echo.%%~^^^!
 ^|^>nul FindStr.EXE /i /b /c:"%%~nxb"
 ^&^&set /a ERR = 0
 ^|^|set /a ERR = 1
 ^&( if ^^^!ERR^^^! neq 0 ( set "%%~c=" ) else set "%%~c=%%~db" )
 ^&( echo. ^&echo. ^&if ^^^!ERR^^^! neq 0 ( set /p "?= Not a valid file : '%%~b' [ERROR:^^^!ERR^^^!]" ^<nul ) else    set /p "?= File : '%%~c' : '^^^!%%~c^^^!' [OK]" ^<nul ) "


for %%? in (  Create.FileName ) do

::testin
set "%%~?=
 echo.b=y%%fo_
"


for %%? in (  Create.Object ) do

::testin
set "%%~?=
 set "Object.Name=%%~b"
 &set "Object.Extension=%%~c"
 &set "Object.Data=%%~d"
 &set "Error.bool=%%~e"
 &echo.
 &echo.Object.Name:^^^!Object.Name^^^!_
 &echo.Object.Extension:^^^!Object.Extension^^^!_
 &echo.Object.Data:^^^!Object.Data^^^!_
 &echo.Error.bool:^^^!Error.bool^^^!_
 &echo.
 &set "Create.Object.Extension=%%Create.^^^!Object.Extension^^^!%%"
 &echo.for /f "usebackq tokens=1-2 delims=¦" %%f in ( '"^^^!Object.Data^^^!"¦"^^^!Object.Name^^^!"' ) do call ^^^!Create.Object.Extension^^^!
 &for /f "usebackq tokens=1-2 delims=¦" %%f in ( '"^^^!Object.Data^^^!"¦"^^^!Object.Name^^^!"' ) do call ^^^!Create.Object.Extension^^^!
"

::works
set "%%~?=
 set "Object.Name=%%~b"
 &set "Object.Extension=%%~c"
 &set "Object.Data=%%~d"
 &set "Error.bool=%%~e"
 &echo.
 &echo.Object.Name:^^^!Object.Name^^^!_
 &echo.Object.Extension:^^^!Object.Extension^^^!_
 &echo.Object.Data:^^^!Object.Data^^^!_
 &echo.Error.bool:^^^!Error.bool^^^!_
 &echo.
 &call set "Create.Object.Extension=%%Create.^^^!Object.Extension^^^!%%"
 &echo. ^^^!Create.Object.Extension^^^!
"


I can't expand

Code: Select all

echo.Post.define: 'Create.FileName' [OK]
for %%? in (  Create.FileName ) do set "%%~?=echo.b=y%%f%%o_"

output:b=y%f%o_ :?:

Re: Optimizations related to Performance

Posted: 19 May 2011 04:34
by jeb
Hi Ed,

my main problem is to understand what are you trying :?:

I understand you try to build an object model with macros.
This could be a good idea, I thought about to build a object-model with calling,
but I discarded it, as I can't find a way to move the data in the different setlocal scopes.

But perhaps you could explain your current problem a bit.

I tried this

Code: Select all

for %%? in (  Create.FileName ) do set "%%~?=echo.b=y%%f%%o_"
%Create.FileName%


Output as expected:

Code: Select all

b=y%f%o_


But what do you expect?

jeb

Re: Optimizations related to Performance

Posted: 19 May 2011 05:47
by Ed Dyreen
That is hust a typo.

define Create.Filename
define Create.Object

%Create.Object% FileName

The problem is:
Passing argument as parameter %%b [OK]
Saving argument to variable '@something' [OK]
Expand variable '@Create.(@Something)' [OK]
Passing this variable as a new %%b parameter [ERROR]
Call other macro '@Create.(@Something)' [OK]

This is where I am stuck

Code: Select all

            set "E7=^^^^^^^"
            set "E10=%E7%^^^"
            set "E15=%E7%%E7%^"
            set "E16=%E15%^"
            set "E29=%E15%%E7%%E7%"
            set "E30=%E15%%E15%"
            set "E31=%E16%%E15%"
            set "E63=%E30%%E30%^^^"
echo.
echo.
echo.FullPath.LocalHost.SCRIPT=!FullPath.LocalHost.SCRIPT!_
echo.
::
echo.Post.define: 'Create.FileName' [OK]
for %%? in (  Create.FileName ) do set "%%~?=echo.b=ybo_"

echo.Pre.define: 'Create.FileName' [OK]

echo.Post.define: 'Create.Object' [OK]
for %%? in (  Create.Object ) do set "%%~?=set "Object.Name=%%~b" &set "Object.Extension=%%~c" &set "Object.Data=%%~d" &set "Error.bool=%%~e" &echo. &echo.Object.Name:^^^!Object.Name^^^!_ &echo.Object.Extension:^^^!Object.Extension^^^!_ &echo.Object.Data:^^^!Object.Data^^^!_ &echo.Error.bool:^^^!Error.bool^^^!_ &echo. &call set "Create.Object.Extension=%%Create.%E7%!Object.Extension%E7%!%%" &echo.^^^!Create.Object.Extension^^^! &for %%^^^! in ( "Create.^^^!Object.Extension^^^!" ) do set "Create.Object.Extension=%E7%!%%~^^^!%E7%!" &%%Create.Object.Extension%%_"

echo.Pre.define: 'Create.Object' [OK]



set /p "?=Pre Execution Create.Object [OK]" <nul
::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Object.Name"   ¦"Object.Extension"   ¦"Object.Data"         ¦"Error.bool"'    ) do %Create.Object% %(>nul)%
  for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Host"¦"FileName"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) do %Create.Object% %(>nul)%
echo.Post Execution Create.Object [OK]

echo.endoftest
pause
exit



set "%%~?=
 echo.%%~^^^!
 ^|^>nul FindStr.EXE /i /b /c:"%%~nxb"
 ^&^&set /a ERR = 0
 ^|^|set /a ERR = 1
 ^&( if ^^^!ERR^^^! neq 0 ( set "%%~c=" ) else set "%%~c=%%~db" )
 ^&( echo. ^&echo. ^&if ^^^!ERR^^^! neq 0 ( set /p "?= Not a valid file : '%%~b' [ERROR:^^^!ERR^^^!]" ^<nul ) else    set /p "?= File : '%%~c' : '^^^!%%~c^^^!' [OK]" ^<nul ) "


for %%? in (  Create.FileName ) do

::testin
set "%%~?=
 echo.b=y%%fo_
"


for %%? in (  Create.Object ) do

::testin
for %%? in (  Create.Object ) do

set "%%~?=
 set "Object.Name=%%~b"
 &set "Object.Extension=%%~c"
 &set "Object.Data=%%~d"
 &set "Error.bool=%%~e"
 &echo.
 &echo.Object.Name:^^^!Object.Name^^^!_
 &echo.Object.Extension:^^^!Object.Extension^^^!_
 &echo.Object.Data:^^^!Object.Data^^^!_
 &echo.Error.bool:^^^!Error.bool^^^!_
 &echo.
 &call set "Create.Object.Extension=%%Create.%E7%!Object.Extension%E7%!%%"
 &echo.^^^!Create.Object.Extension^^^!
 &echo.for %%%E7%! in ( "Create.^^^!Object.Extension^^^!" ) do set "Create.Object.Extension=%%%E7%!"
 &echo.Create.Object.Extension=^^^!Create.Object.Extension^^^!_
"

 &echo.for %%%E7%! in ( 'echo.%E7%!Create.Object.Extension%E7%!' ) do set "Create.Object.Extension=%E7%!Create.^^^!Object.Extension^^^!%E7%!"

 &set "Create.Object.Extension=%E15%!Create.%E7%!Object.Extension%E7%!%E15%!"

 &echo.for /f "usebackq tokens=1-2 delims=¦" %%%E7%b in ( '"%E7%!Object.Data%E7%!"¦"%E7%!Object.Name%E7%!"' ) do echo.%E7%!Create.Object.Extension%E7%!

 &for /f "usebackq tokens=1-2 delims=¦" %%^^^b in ( '"%E7%!Object.Data%E7%!"¦"%E7%!Object.Name%E7%!"' ) do %E7%!Create.Object.Extension%E7%!

 &for /f "usebackq tokens=1-2 delims=¦" %%^^^b in ( '"%E7%!Object.Data%E7%!"¦"%E7%!Object.Name%E7%!"' ) do call ^^^!Create.Object.Extension^^^!

 &echo.for %%%E7%b in ( "^^^!Object.Extension^^^!" ) do set "Create.Object.Extension=!Create.%%~%E63%b!"

::works

set "%%~?=
 set "Object.Name=%%~b"
 &set "Object.Extension=%%~c"
 &set "Object.Data=%%~d"
 &set "Error.bool=%%~e"
 &echo.
 &echo.Object.Name:^^^!Object.Name^^^!_
 &echo.Object.Extension:^^^!Object.Extension^^^!_
 &echo.Object.Data:^^^!Object.Data^^^!_
 &echo.Error.bool:^^^!Error.bool^^^!_
 &echo.
 &set "Create.Object.Extension=%E15%!Create.%E7%!Object.Extension%E7%!%E15%!"
 &echo.for %%%E7%! in ( 'echo.%E7%!Create.Object.Extension%E7%! ) do echo.set "Create.Object.Extension=%E7%!Create.^^^!Object.Extension^^^!%E7%!"
"


But I think I can solve it, not now though
I need to study &Some of our guests too!
If noone responds to your question, well it is either a really stupid question.
Or noone is specialized in the matter.
People respond if they think it is a mutual exchange of knowledge.
:idea:

Think I may already have solved it in !Err.Chk.RegRead! !Err.Chk.IsDefined!

A macro is being called @Err.Chk.IsDefined from @Err.Chk.RegRead with a different %%b than the original %%b that was our input

@jeb
But what do you expect?

It was a long day yesterday, &obviously i suffered exhaustion

Re: Optimizations related to Performance

Posted: 19 May 2011 09:13
by Ed Dyreen
Aaargh stuck again :evil:
This is not simply calling a macro from within a macro. This is about calling a variable macro from within a macro.
If I can't overcome this. then this means game over!

Code: Select all

            set "E7=^^^^^^^"
            set "E10=%E7%^^^"
            set "E15=%E7%%E7%^"
            set "E16=%E15%^"
            set "E29=%E15%%E7%%E7%"
            set "E30=%E15%%E15%"
            set "E31=%E16%%E15%"
            set "E63=%E30%%E30%^^^"
echo.
echo.
echo.FullPath.LocalHost.SCRIPT=!FullPath.LocalHost.SCRIPT!_
echo.
::
echo.Post.define: 'Create.Object' [OK]
for %%? in (  Create.Object ) do set "%%~?=set "Object.Name=%%~b" ^&set "Object.Extension=%%~c" ^&set "Object.Data=%%~d" ^&set "Error.bool=%%~e" ^&echo. ^&echo.Object.Name:^^^!Object.Name^^^!_ ^&echo.Object.Extension:^^^!Object.Extension^^^!_ ^&echo.Object.Data:^^^!Object.Data^^^!_ ^&echo.Error.bool:^^^!Error.bool^^^!_ ^&echo. ^&for /f "tokens=*" %%^^^! in ( '^^^!Create.%%~c^^^! %()%' ) do for %%^^^b in ( "^^^!Object.Extension^^^!" ) do echo.%%~^^^b ^&echo.%%~^^^!"

echo.Pre.define: 'Create.Object' [OK]


echo.Post.define: 'Create.FileName' [OK]
for %%? in (  Create.FileName ) do set "%%~?=echo.Hello &echo.lo &echo.%%~^b"


echo.Pre.define: 'Create.FileName' [OK]


set /p "?=Pre Execution Create.Object [OK]" <nul
::for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Object.Name"   ¦"Object.Extension"   ¦"Object.Data"         ¦"Error.bool"'    ) do %Create.Object% %(>nul)%
  for /f "usebackq tokens=1-4 delims=¦" %%b in ( '"Host"¦"FileName"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) do %Create.Object% %(>nul)%


echo.Post Execution Create.Object [OK]


echo.endoftest
pause
exit


for %%? in (  Create.FileName ) do

::testin
set "%%~?=
 echo.Hello
 &echo.lo
 &echo.%%~^^^!
"

::works
set "%%~?=
 echo.Hello
 &echo.lo
"

for %%? in (  Create.Object ) do

::testin
set "%%~?=
 set "Object.Name=%%~b"
 ^&set "Object.Extension=%%~c"
 ^&set "Object.Data=%%~d"
 ^&set "Error.bool=%%~e"
 ^&echo.
 ^&echo.Object.Name:^^^!Object.Name^^^!_
 ^&echo.Object.Extension:^^^!Object.Extension^^^!_
 ^&echo.Object.Data:^^^!Object.Data^^^!_
 ^&echo.Error.bool:^^^!Error.bool^^^!_
 ^&echo.
 ^&for /f "tokens=*" %%^^^! in ( '^^^!Create.%%~c^^^! %()%' ) do for %%^^^b in ( "^^^!Object.Extension^^^!" ) do echo.%%~^^^b ^&echo.%%~^^^!
"

::works
set "%%~?=
 set "Object.Name=%%~b"
 ^&set "Object.Extension=%%~c"
 ^&set "Object.Data=%%~d"
 ^&set "Error.bool=%%~e"
 ^&echo.
 ^&echo.Object.Name:^^^!Object.Name^^^!_
 ^&echo.Object.Extension:^^^!Object.Extension^^^!_
 ^&echo.Object.Data:^^^!Object.Data^^^!_
 ^&echo.Error.bool:^^^!Error.bool^^^!_
 ^&echo.
 ^&for /f "tokens=*" %%^^^! in ( '^^^!Create.%%~c^^^! %()%' ) do echo.%%~^^^!"
"


2nd macro output :
Hello
Lo
%~b

%~b should expand to @Object.Extension: 'Filename' but it fails.

Re: Optimizations related to Performance

Posted: 19 May 2011 13:56
by jeb
Hi Ed,

I can't follow your code, it's too much. :?
A smaller sample could be helpful :)

But I assume that you try something like

Code: Select all

echo on
for %%a in ("indirect=%%X") do for %%X in (1 2) do echo direct=%%X %%~a

Output:

Code: Select all

1: C:\temp>for %a in ("indirect=%X") do for %X in (1 2) do echo direct=%X %~a
2:
3: C:\temp>for %X in (1 2) do echo direct=%X indirect=%X
4:
5: C:\temp>echo direct=1 indirect=%X
6: direct=1 indirect=%X
7:
8: C:\temp>echo direct=2 indirect=%X
9: direct=2 indirect=%X


Line 3 is the important one.
Although after the first expansion you got echo direct=%X indirect=%X, you can see in line 5 that the indirect %X isn't expanded again.

This seems to be an effect of the FOR-LOOP parsing.
I believe, that all %%vars and there positions are saved at the parse time, before executing the (outer) for-loop.
So you can't add new %%vars at "runtime" with delayed or %%var expansion.
Percent-expansion (%var%) is not affected, as it is the first step of the parsing of the block.

Code: Select all

echo on
for %%b in (BBB) do (
   for /F "tokens=1,2" %%a in ("AAA CCC") do (   
      echo %%a %%b
   )
)


output:

Code: Select all

1: C:\temp>for %b in (BBB) do (for /F "tokens=1,2" %a in ("AAA CCC") do (echo %a %b ) )
2: C:\temp>(for /F "tokens=1,2" %a in ("AAA CCC") do (echo %a BBB ) )
3: C:\temp>(echo AAA CCC )
4: AAA CCC

In line 2 the echo %%a %%b is seems to be expanded to echo %a BBB, but then the parser change his mind and change the BBB to CCC :o

Perhaps this is your problem, ... or not :)

jeb

Re: Optimizations related to Performance

Posted: 19 May 2011 14:02
by Ed Dyreen
I posted a working demo sample in the related forum : 'Batch "macros" with arguments'
http://www.dostips.com/forum/viewtopic.php?f=3&t=1827
Maybe someone can close this thread because they handle the same topic.