I have a particularly thorny problem for you guys.
I am making a function which can modify batch file function calls.
I have identified 3 types of function calls and I need to change any one type to another.
Here are the name I gave to batch function calls
Internal function call
Code: Select all
Call :myfunction
Code: Select all
Call myfunction.bat
Code: Select all
Call %:myfunction%
Anyway, here is the actual problem
I have in memory the entire batchfile, line by line. Here is an particularly vexing example.
Code: Select all
set "textline=Call :myfunctiona some args & Call %:myfunctionb% some args & Call myfunctionc.bat some args & Call :myfunctiond some args && echo yes || echo no
Example
Code: Select all
Call :ChangeInternalFunctionToExternal textline
Call :ChangeInternalFunctionToMacroCall textline
Call :ChangeExternalFunctionToInternal textline
Call :ChangeExternalFunctionToMacroCall textline
Call :ChangeMacroCallFunctionToInternal textline
Call :ChangeMacroCallFunctionToExternal textline
Code: Select all
textline=Call myfunctiona.bat some args & Call %:myfunctionb% some args & Call myfunctionc.bat some args & Call myfunctiond.bat some args && echo yes || echo no
Code: Select all
textline=Call %:myfunctiona% some args & Call %:myfunctionb% some args & Call myfunctionc.bat some args & Call %:myfunctiond% some args && echo yes || echo no
Code: Select all
textline=Call :myfunctiona some args & Call %:myfunctionb% some args & Call :myfunctionc some args & Call :myfunctiond some args && echo yes || echo no
Code: Select all
textline=Call :myfunctiona some args & Call %:myfunctionb% some args & Call %:myfunctionc% some args & Call :myfunctiond some args && echo yes || echo no
Code: Select all
textline=Call :myfunctiona some args & Call :myfunctionb some args & Call myfunctionc.bat some args & Call :myfunctiond some args && echo yes || echo no
Code: Select all
textline=Call :myfunctiona some args & Call myfunctionb.bat some args & Call myfunctionc.bat some args & Call :myfunctiond some args && echo yes || echo no
https://stackoverflow.com/questions/510 ... batch-file
I tried the substring substitution trick, however, I am unsure if that is even possible due to the number of poison characters in the string
I tried a basic test
Code: Select all
@echo off
set "string=Call :myfunctiona & Call %:myfunctionb% & Call myfunctionc.bat & Call :myfunctiond && echo yes || echo no
set string
set "x=%string:Call :=" & set "substring=%"
set substring
set "x=%string:Call %=" & set "substring=%"
set substring
set "x=%string:Call =" & set "substring=%"
set substring
goto :eof
Code: Select all
string=Call :myfunctiona & Call :myfunctionbmyfunctiond && echo yes || echo no
substring=myfunctionbmyfunctiond && echo yes || echo no
substring=myfunctionbmyfunctiond && echo yes || echo no
substring=:myfunctionbmyfunctiond && echo yes || echo no