Steve6375 said:
You say '%@retval% does not exist if first two bytes'
but %@retval% always 'exists' - it is a number - it may be 0 or a negative or positive integer???
@steve6375
I have tested my 'problem' again. You are right (of course), I was mistaken. Because of the logical operator (&& or || or &; or |;) I simply couldn't get it if the operator 'stops' executing the read-out-command.
So I will have to read-out %@retval% from a new line or after ;; (or give it a predefined value if the line is only executed if an preceding if-statement is true and I need a %@retval%-counter-value in lines afterwards if %@retval% isn't read-out (0 if using && or &; 1 if using || or |; ??).
But I believe you are against such a solution?
Solutions calling a sub-routine or use if command goto :label to skip the lines related to the read-out %@retval% are possible of course, I sometimes use them. But will cost one label each time, and only 128 labels are supported - isn't it.
I have to deal with the constraints of Grub4Dos-scripting (I am aware off): 2000 lines, 60 (regular) variables, 128 labels and 1535/1536 chars on a line. With my current script I am reaching limits, and still not I all functionality I want to implement 'onboard'. I don't know a better solution than to making lines longer.
As a personal side-note: my eldest son, who is working as a professional programmer, sometimes laughs at me and say i have to learn C/C++ and write my scripts in that language and compile them for use on the Grub4Dos command-line. I still want to 'escape' this fate.
Steve6375 said:
why use &; when you are not testing the length of the variable entrylen which will be '0x0' at the shortest and so the result will always be 3 or more = true!
What i like about Grub4dos-scripting it's so close to ordinary thought (at least my ordinary way of thinking). I am just an 'ordinary Joe' and not a programmer. So to not to be misunderstood: I have not intention to lecture or criticize anyone, especially not steve6375, whose work I owe so much! Also I am very happy to be criticized, very helpful for me. Also give me ideas for new experiments to evaluate the way I am using Grub4dos-operators, and to find out 'what's in it for me'.
In my 'logical universe' I use &; in the following way: 'If the preceding command is true, refresh variables and execute next command'. In case of setting some numerical value from %@retval%, &; is mandatory (as far I understand this subject).
Also I found that set (....) && ALWAYS returns %@retval%=1. Even with set a= or after set a= && set a=%a% &&
The case of set a= && set a=%a% &; echo %@retval% is a bit strange. Even if variable a doesn't exist, %@retval% still returns 1. But luckily it's consistent with my use of && and &; instead of the ;;-operator.
There is a practical advantage too: if working on big scripts like mine with length of lines up to more than 800 chars (800 in one single case), I just can use ONE # to comment out a whole line and try another-one. That's another reason why I am 'not so fond of' the ;;-operator. Although I will fully understand if any programmer will burst out laughing.
Steve6375 said:
no need for && as you already use if
if (test) (command)
I have tested this use of the if-command, but I 'can't live with it'. See following test:
grub> set a=A
grub> if %a%==A echo YES
YES
grub> set a=
grub> if %a%==A echo YES
Error 30: (http://grub4dos.chenall.net/e/30)
invalid argument
grub> if %a%==A && echo YES
grub> _
I my editor-script I have a variable 'menu' to held the choice of a sub-menu from the main menu. Also I use variables 'read' 'edit' and 'write' to held the choices in their respective sub-menu's. Variables 'read' 'edit' and 'write' share many subroutines, if using 'if (test) (command)' I always have to test the existence of the variable to be evaluated first (only if not is 'safe').
With my &&-work-around this not needed (if believe you say in your book && is only mandatory in conjunction with !). I never ran into problem's with my &&-method.
Steve6375 said:
grub4dos really needs a if [TEST] { command ; command ;; command } type operator so you can have multiple commands based on an if result. I think the latest grub4efi understands braces to group multiple commands but not sure if the latest grub4dos version does?
I looked in the latest version of Grub4Dos 0.4.6a 2021-06-02: can't find it.
Steve6375 said:
if %call%==Y && set called=Y && call :refresh1 && echo 1.2 goback=%goback%
The first thing the grub4dos parser does is to replace all %xxxx% parameters (unless there is a ^ character inside the parameter)
Thanks a lot
Now I understand why I ran into problems!
Steve6375 said:
but there is no need to use && because you are not testing anything - so just use ;;
if %call%==Y set called=Y ;; call :refresh1 ;; echo 1.2 goback=%goback%
If my preceding line set call=Y meant 'you are not testing anything' I understand.
I did some new tests, see below for the lines and screen-output:
!BAT
#REFRESH2.G4B Test call's
debug 0
clear
set call=zyx && set goback=
set /p "call= Test call's: Y=yes N=no > " && echo
if not %call%==Y if not %call%==N goto :eof
if %call%==Y set called=Y ;; call :refresh1 ;; echo 1.2 goback=%goback%
echo 1.3 goback=%goback%
goto :eof
:refresh1
echo 1.1 called=%called%
set goback=Y
goto :eof
:eof
Screen-output I
Test call's: Y=yes N=no > Y
1.1 called=Y
1.2 goback=Y
1.3 goback=Y
grub> _
Screen-output II
Test call's: Y=yes N=no > N
1.1 called=Y
1.2 goback=Y
1.3 goback=Y
grub> _
!BAT
#REFRESH3.G4B Test call's
debug 0
clear
set call=zyx && set goback=
set /p "call= Test call's: Y=yes N=no > " && echo
if not %call%==Y if not %call%==N goto :eof
if %call%==Y set called=Y && call :refresh1 &; echo 1.2 goback=%goback%
echo 1.3 goback=%goback%
goto :eof
:refresh1
echo 1.1 called=%called%
set goback=Y
goto :eof
:eof
Screen-output I
Test call's: Y=yes N=no > Y
1.1 called=Y
1.2 goback=Y
1.3 goback=Y
grub> _
Screen-output II
Test call's: Y=yes N=no > N
1.3 goback=
grub> _
Solution with call:
if %call%==Y && set called=Y && call :refresh1 && call echo 1.2 goback=%^goback%
give same result as REFRESH3.G4B.
Again: steve6375, thanks a lot, everything you said was very helpful.
BTW this is my first use of the quote-function while posting, don't see a possibility to add date/time 'automagically'