I made simple to use helper function, to determine if a function is a "base" function or an alias.
Also to obtain a list of alias related to a specific base function.
First, what is a function
Code: Select all
:Hello
echo Hello,world
GoTo :EOF
Code: Select all
::Usage Call :Hello
::Prints Hello,world
::This is the preamble text
:Hello
echo Hello,world
GoTo :EOF
REM this is the post-script text
REM The text from the function label and the last exit, I call the function "body" text
An alias if a function label, which is placed before the "base" function label and DOES NOT have an exit (continues into the base function without a goto or call ). Here you will probably set a mode switch to superficially change the internal logic of the function.
Here is an example alias for hello world
Code: Select all
::Usage Call :Hello
::Usage Call :Allo
:Allo
set _Hello_mode=french
:Hello
if not defined set _Hello_mode ( echo Hello,world ) else ( if "[%_Hello_mode%]" EQU "[french]" echo Salut,monde )
GoTo :EOF
Code: Select all
::Usage Call :GetBasefunction BatchFile FunctionName ReturnVariable
::Usage Call :GetFunctionAliases batchfile functionname returnvariable
::Usage Call IsBaseFunction BatchFile FunctionName optional ReturnVariable && echo Function is base function || echo function is not base function
::Usage Call IsFunctionAlias BatchFile FunctionName optional ReturnVariable && echo Function is alias || echo function is not alias
Relating to the above example you would use it as follows
GetBasefunction returns the name of the base function in the return variable, and the line number of the base function label in errorlevel
Code: Select all
Call :GetBasefunction %~dpnx0 Allo ReturnVariable
echo %errorlevel%
echo %ReturnVariable%
75
Hello
Code: Select all
Call :GetFunctionAliases %~dpnx0 hello returnvariable
echo %errorleve%
echo %returnvariable%
1
Allo
Optionally, you can put in a returnvariable and get "true" or "false" in that variable
Code: Select all
Call IsBaseFunction %~dpnx0 hello && echo Function is base function || echo function is not base function
Function is base function
Call IsBaseFunction %~dpnx0 allo && echo Function is base function || echo function is not base function
function is not base function
Call IsFunctionAlias %~dpnx0 hello && echo Function is alias || echo function is not alias
function is not alias
Call IsFunctionAlias %~dpnx0 allo returnvariable && echo Function is alias || echo function is not alias
Function is alias
echo %returnvariable%
true
In the provided files you will find a functionswitcher, which allows you to call the function, based on the name of the batch file.
"bfw" is a special name the batch file could have, in that case, it will call the function named in the first argument as well as shift the arguments
Code: Select all
@echo off
:setup
:main
for %%a in ( %* ) do ( for %%b in ( /h /? -h -? help --help ) do ( if "[%%a]" EQU "[%%b]" ( Call :%~n0-help & exit /b 1 ) ) )
for %%a in ( %* ) do ( if "[%%a]" EQU "[demo]" ( Call :%~n0-demo & exit /b 1 ) )
if "[%~1]" EQU "[]" ( echo %~n0 needs at least one argument & exit /b 1 )
if "[%~n0]" EQU "[bfw]" ( Call :ShiftedArgumentCaller %* ) else ( Call :%~n0 %* )
:end
exit /b %errorlevel%
The end result is you can have multiple copies of the same file, create symlinks to it with different name. This is a lot like the linux busybox utility, which performs many tasks in one executable.
The zip file, cannot have symlinks, so it has multiple copies of the same file with different names.
In practical terms, this means you can use it as follows
Testing IsBaseFunction and IsFunctionalias
Code: Select all
call IsBaseFunction.bat IsBaseFunction.bat IsBaseFunction && echo It is base function || echo it is not base function
It is base function
call IsBaseFunction.bat IsBaseFunction.bat isfunctionalias && echo It is base function || echo it is not base function
it is not base function
call IsFunctionalias.bat IsBaseFunction.bat isbasefunction && echo It is function alias || echo it is not function alias
it is not function alias
call IsFunctionalias.bat IsBaseFunction.bat isfunctionalias && echo It is function alias || echo it is not function alias
It is function alias
Code: Select all
IsBaseFunction-demo.bat IsBaseFunction.bat
Function ShiftedArgumentCaller is a base function.
Function Hello is a base function.
Function PrintWithoutNewline is a base function.
Function GetFunctionAliases-demo is a base function.
Function IsBaseFunction-demo is a base function.
Function IsFunctionAlias is not a base function. Base function:IsBaseFunction
Function IsBaseFunction is a base function.
Function GetBaseFunction-demo is a base function.
Function GetBaseFunctionRow is not a base function. Base function:GetBaseFunction
Function GetBaseFunctionName is not a base function. Base function:GetBaseFunction
Function GetBaseFunction is a base function.
Function DoesFunctionHaveAliases is a base function.
Function GetFunctionAliases is a base function.
Function IsFile is a base function.
Function GetFunctionRows is a base function.
Function GetLabelRow is a base function.
Function GetFunctionExit is a base function.
Function GetFunctionPreambleRow is a base function.
Function GetFunctionPostscriptRow is a base function.
Function ClearVariablesByPrefix is a base function.
Function GetFunctionName is a base function.
Function GetBatchCore is a base function.
Function GetNextExitRow is a base function.
Function ListFunctions is a base function.
Function GetPreviousFunctionName is not a base function. Base function:GetPreviousFunctionRow
Function GetPreviousFunctionRow is a base function.
Function GetNextFunctionName is not a base function. Base function:GetNextFunctionRow
Function GetNextFunctionRow is a base function.
Function GetPreviousExitRow is a base function.
Function GetEOFrow is a base function.
Function countLines is a base function.
Function IsFunctionLabelExcluded is a base function.
Function GetPreviousEmptyRow is a base function.
Function GetNextEmptyRow is not a base function.
Code: Select all
GetFunctionAliases-demo.bat IsBaseFunction.bat
Test functions ShiftedArgumentCaller Hello PrintWithoutNewline GetFunctionAliases-demo IsBaseFunction-demo IsFunctionAlias IsBaseFunction GetBaseFunction-demo GetBaseFunctionRow GetBaseFunctionName GetBaseFunction DoesFunctionHaveAliases GetFunctionAliases IsFile GetFunctionRows GetLabelRow GetFunctionExit GetFunctionPreambleRow GetFunctionPostscriptRow ClearVariablesByPrefix GetFunctionName GetBatchCore GetNextExitRow ListFunctions GetPreviousFunctionName GetPreviousFunctionRow GetNextFunctionName GetNextFunctionRow GetPreviousExitRow GetEOFrow countLines IsFunctionLabelExcluded GetPreviousEmptyRow GetNextEmptyRow
Function ShiftedArgumentCaller is a base function.
Function Hello is a base function.
Function PrintWithoutNewline is a base function.
Function GetFunctionAliases-demo is a base function.
Function IsBaseFunction-demo is a base function.
Function IsFunctionAlias is not a base function. Base function:IsBaseFunction
Function IsBaseFunction is a base function.
Function IsBaseFunction has aliases
Function IsBaseFunction aliases: IsFunctionAlias
Function GetBaseFunction-demo is a base function.
Function GetBaseFunctionRow is not a base function. Base function:GetBaseFunction
Function GetBaseFunctionName is not a base function. Base function:GetBaseFunction
Function GetBaseFunction is a base function.
Function GetBaseFunction has aliases
Function GetBaseFunction aliases: GetBaseFunctionName GetBaseFunctionRow
Function DoesFunctionHaveAliases is a base function.
Function GetFunctionAliases is a base function.
Function IsFile is a base function.
Function GetFunctionRows is a base function.
Function GetLabelRow is a base function.
Function GetFunctionExit is a base function.
Function GetFunctionPreambleRow is a base function.
Function GetFunctionPostscriptRow is a base function.
Function ClearVariablesByPrefix is a base function.
Function GetFunctionName is a base function.
Function GetBatchCore is a base function.
Function GetNextExitRow is a base function.
Function ListFunctions is a base function.
Function GetPreviousFunctionName is not a base function. Base function:GetPreviousFunctionRow
Function GetPreviousFunctionRow is a base function.
Function GetPreviousFunctionRow has aliases
Function GetPreviousFunctionRow aliases: GetPreviousFunctionName
Function GetNextFunctionName is not a base function. Base function:GetNextFunctionRow
Function GetNextFunctionRow is a base function.
Function GetNextFunctionRow has aliases
Function GetNextFunctionRow aliases: GetNextFunctionName
Function GetPreviousExitRow is a base function.
Function GetEOFrow is a base function.
Function countLines is a base function.
Function IsFunctionLabelExcluded is a base function.
Function GetPreviousEmptyRow is a base function.
Function GetNextEmptyRow is not a base function.'"_DFHA_result=false"' is not recognized as an internal or external command,
operable program or batch file.
Function GetNextEmptyRow has aliases
The syntax of the command is incorrect.
In the zip file you will find the following files
These are all the same file with different names
Code: Select all
GetFunctionAliases-demo.bat
IsBaseFunction.bat
IsBaseFunction-demo.bat
IsFunctionAlias.bat
Code: Select all
bfw.bat
For the current purpose you would use it as such
Code: Select all
call bfw IsBaseFunction bfw.bat IsBaseFunction && echo It is base function || echo it is not base function
It is base function
call bfw IsBaseFunction bfw.bat IsFunctionAlias && echo It is base function || echo it is not base function
it is not base function
call bfw IsFunctionAlias bfw.bat IsBaseFunction && echo It is function alias || echo it is not function alias
it is not function alias
call bfw IsFunctionAlias bfw.bat IsFunctionAlias && echo It is function alias || echo it is not function alias
It is function alias