Hi Guys,
I am developing a code where function "done_send_to_engine" will take either single or double inputs
so before sending to this function I'll check whether they are null or not using below script snippet
Input Menu
Enter IP's
Start :
End :
so after taking the IP's from the above menu I'll check whether there are 2 IP's or only single IP
single IP can be entered either on Start or End so my code checks and pass it to my processing engine function "done_send_to_engine". If both are filled Start and End then my engine function will pin sweep all those IP's
if either Start or End are entered then my engine will ping only that machine. please review my below code and
check whether any further optimizations can be done.
:validate_inputs
SETLOCAL
set val_1=%1
set val_2=%2
if "%val_1%" EQU "" (set val1=0&&call:check_val_2) else (set val1=1&&call:check_val_2)
:check_val_2
if "%val1%" EQU 0 (call:check_val_2_for_0)
if "%val1%" EQU 1 (call:check_val_2_for_1)
:check_val_2_for_0
if "%val_2%" EQU "" (call:null_input) else (call:done_send_to_engine %val_2%)
:check_val_2_for_1
if "%val_2%" EQU "" (call:done_send_to_engine %val_1%) else (call:done_send_to_engine %val_1% %val_2%)
ENDLOCAL
Thanks
Please check this code for any further optimization
Moderator: DosItHelp
Re: Please check this code for any further optimization
BVKmohan,
how about simply:
if both %1 and %2 are empty then the concatenation "%1%2" will be empty and the condition be TRUE.
Otherwise:
if %1 is empty then %1 resolves to an empty string and you end up with "call:done_send_to_engine %2"
The extra space you get in the argument list should not hurt.
if %2 is empty then %2 resolves to an empty string and you end up with "call:done_send_to_engine %1 "
The extra space you get in the argument list should not hurt.
if both %1 and %2 are set then you end up with "call:done_send_to_engine %1 %2"
DosItHelp?
how about simply:
Code: Select all
if "%1%2" EQU "" (call:null_input) else (call:done_send_to_engine %1 %2)
if both %1 and %2 are empty then the concatenation "%1%2" will be empty and the condition be TRUE.
Otherwise:
if %1 is empty then %1 resolves to an empty string and you end up with "call:done_send_to_engine %2"
The extra space you get in the argument list should not hurt.
if %2 is empty then %2 resolves to an empty string and you end up with "call:done_send_to_engine %1 "
The extra space you get in the argument list should not hurt.
if both %1 and %2 are set then you end up with "call:done_send_to_engine %1 %2"
DosItHelp?
Re: Please check this code for any further optimization
Yes ! you made it simple
Thanks for the help
Thanks for the help