Jump to content











Photo
- - - - -

Writing to the Grub4dos' keyboard buffer possible?

grub4dos

  • Please log in to reply
110 replies to this topic

#101 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 20 August 2021 - 04:39 PM

Only a pet-peeve of mine, generically speaking (for batch files) the :help subroutine labels should actually be (IMHO):

:--h

:--help

:/?

first two are *nix (and GRUB/grub4dos) style, whilst the third is Dos/NT style

 

 

or - even better - put an early check for the absence of parameters, i.e. all in all, *something like* this would do nicely:

!BAT
if %1.==. goto :/?
call :%~1 %*
#...
goto :eof

:/?
:--h
:--help
echo this is help
goto :eof

but in the case of a .lll (lousy linked library) I wonder if it is useful, after all the general idea of a library is to be called by another batch, rather than on command line :dubbio:

 

 

:duff:

Wonko 



#102 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 20 August 2021 - 05:57 PM

My idea with the help-argument was to have easy access to the 'documentation' of a single function. Even version specific and easy to update!

While writing a function everything seems easy-going to me, but after a while I tend to forget many details. For instance I just finished text-function CntRemark (only at begin af a line). I thought it a good idea to recycle parts of CntLabel (three weeks ago in this thread), but quick access from the Grub4Dos command-line to the arguments (to 'refresh' my idea's) wasn't available.

As soon functions are collected in one, or a few different files, a .doc-file have to be written?

For now I prefer producing functions. If there are 'enough', good class-abbreviations can be considered to group the functions.

BTW I will think about the exact syntax of a help-argument. I like '/?' most, because its faster on desktop keyboard (can be my personal preference).

An extra if-statement will make a function slower, but should be (loop-)tested. Unless there is a way to pass the call-error if label is not found...?

#103 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 21 August 2021 - 08:41 AM

Yep, but again for a normal executable or for a batch intended to be called directly from the command line some basic help is (IMHO) *needed* and the easiest it can be shown to the user (like executing the file without parameters or using a switch like /?) the better.

 

For libraries it would make (still IMHO) more sense to use a convention, *like* - say - #-# to mark the comment lines that actually contain the help/parameters details and then have a "helper" command/batch that shows them.

 

Again in NT batch that would be as easy as (in NT I usually have ::# as marker)

type <batch> | FIND "::#"

 

First, simplest thingy I could come up with:

!BAT
#-# showfunc.g4b to view lines in .lll's marked with the # - # sequence
#-# (without spaces), 
#-# i.e. containing information about contained functions and parameters
#-# parameters: <target file> [<function name>]
#-# the sequence must be followed by a space
setlocal
set target=%~f1
cat --locate="\x23\x2D\x23 %2" %target% | call :do_lines 
goto :eof

:do_lines
#-# do_lines subroutine to show informational lines
cat --skip=0x%1 %target% | set thisline=
echo %thisline%
shift
if not %1.==. goto :do_lines
goto :eof

Only briefly tried on itself, but it seemingly works just fine.

 

 

:duff:

Wonko



#104 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 21 August 2021 - 11:16 PM

Very nice script!

 

I have changed one .lll, works fine:

Limbo x86 PC Emulator
grub> SHOWFUNC.G4B STRREPL.LLL
STRREPL.LLL v0.1 (20210811), by deomsh. Based on script str_repl.g4b by Wonko th
e Sane
StrReplace
Function: Searches string in string and replace, result is string after replacem
ent(s)
Use: StrReplace string find replace [N|all]
Mandatory Arguments: string find replace, all strings, if containing spaces: bet
ween double quotes!
Optional Arguments: N|all, max number of searchings & replacements (default is 1)
Remarks: Max (output) length max 511 chars in a string.
grub>
grub> SHOWFUNC.G4B STRREPL.LLL StrReplace
StrReplace
grub>
grub> CNTREM.LLL CntRemark STRREPL.LLL "#-#"
grub> set result
result=7
grub>


BTW I changed %thisline% to %thisline:~3% (trailing spaces will be only echod with color-code).

BTW2 Maybe 'locatei' ? Labels are not case sensitive, so .lll functions neither).

 

I was more thinking in the direction of an 'info'-suffix to .lll-name, can be forwarded too. Like this:

Limbo x86 PC Emulator
grub> GETLEAPE.LLL GetLeapInfo
GETLEAP.LLL v0.4 (20210821), by deomsh.
Functions: GetLeapYear, GetLeapSecond, GetLeapSecondCum
Use: GetLeapYear <yyyy>
Use: GetLeapSecond <yyyy> [<mm>]
Use: GetLeapSecondCum <yyyy>
Mandatory Arguments: <yyyy>
Optional Arguments: <mm> only with GetLeapSecond (some years from July, 1)
Remarks: Leap-seconds: in database known until juli 2021.
grub>
grub> GETLEAPE.LLL GetLeapInfo GetLeapYear
Use: GetLeapYear <yyyy>
grub>
grub> GETLEAPE.LLL GetLeapInfo GetLeapSecond
Use: GetLeapSecond <yyyy> [<mm>]
grub>
grub> GETLEAPE.LLL GetLeapInfo GetLeapSecondCum
Use: GetLeapSecondCum <yyyy>
grub>

BTW I changed GETLEAP.LLL, contains three functions now, seems less complex (baseyear with GetLeapSecondCum is in fact not needed: function can called twice to calculate difference).



#105 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 August 2021 - 09:01 AM

Yep. :)

 

locatei seems a nice bettering, as well as the %var:~3% removing of the line incipit.

 

For the usage with the optional second parameter (name of the function) we could add a third (optional-optional) parameter with the number of lines to be shown after the one with the name of the function, or - easier - with a default of - say - following 5 lines beginning with #-# as long as they are no more than (say) 80 characters apart from each other.

 

This way, if you use the second argument, you will see the line where the function is and its usage.

 

In the case of a .lll (as I visualize it) you DO NOT have (like in your example) a "summary" of the functions contained in the .lll (that would be a PITA when/if you add new functions to a .lll), since each function starts with a label with the name of the function, we could adopt a convention *like*:

:label

#-#+ first line after the function label containing as first string the same function name followed by a very brief description (please note the + sign)

#-# second line with some extended description and/or parameters (please note the - sign)

#-# third line with some extended description and/or parameters

#-# fourth line as above

#-# fifth line as above

#-# sixth line as above

 

The %var:~3% would need to be integrated by something *like* if %var:~0,1%.==+. set var=%var:~1%  

 

As a matter of fact we could then also introduce (like it happens with *real* .dll's) the call by ordinal :w00t:

 

It may seem a little thing, but calling /mynice.lll :F12 is much shorter than - say - /mynice.lll :GetLeapSecondCum and bytes are precious.

*like*:

:F02

:GetLeapSecond

#-#+ F02 - GetLeapSecond <yyyy> [<mm>] - returns number of leap seconds since ....
#-# Mandatory Arguments: <yyyy> - year
#-# Optional Arguments: <mm> (some years from July, 1)
#-# Remarks: Leap-seconds: in database known until juli 2021.

 

BTW, this latter way with an optional + parameter (added to the locatei in cat) we can get just a (compact) list of the functions in a .lll, sort of an index

 

:duff:

Wonko

 

P.S.: Ok, quickly put together and needs optimization/cleaning but there is the idea:





!BAT
#-#+ showfunc.g4b to view lines in .lll's marked with the # - # sequence
#-# (without spaces), 
#-# i.e. containing information about contained functions and parameters
#-# parameters: <target file> [<function name>]|[+]
#-# the sequence must be followed by a space
#-# the optional + means "show list of functions in the file"
setlocal
set target=%~f1
set locate=%2
set /a cnt=1 >nul
set /a skip=0 > nul
if %2.==. goto :no_params 
if %2.==+. goto :param+
cat --locatei=" %locate%" %target% | call :do_single 
goto :eof

:no_params
set locate=\x23\x2D\x23
cat --skip=%skip% --locatei="%locate%" %target% | call :do_lines
goto :eof 

:param+
set locate=\x23\x2D\x23\x2B
cat --locatei="%locate%" %target% | call :do_lines
goto :eof 


:F01
:do_lines
#-#+ F01 - do_lines subroutine to show informational lines
#-# parameters are the output of a cat --locate command
cat --skip=0x0%1 %target% | set thisline=
if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3%  
shift
if not %1.==. goto :do_lines
goto :eof

:F02
:do_single
#-#+ F02 - do_single subroutine to show informational lines of a single function
#-# parameters are the output of a cat --locate command
#-# but a (valid) function name or number
#-# must have been passed to the command line
call Fn.12 %locate%
if %@retval%==3 set /A skip=0x0%1-5 > nul
call Fn.12 %locate%
if %@retval%>=4 set /A skip=0x0%1-5-6 > nul
cat --skip=%skip% %target% | set thisline=
if not %thisline:~0,3%==#-# set thisline=
if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3% 
shift
if not %1.==. goto :do_single
set locate=\x23\x2D\x23
cat --skip=%skip% --locatei="%locate%" %target% | call :more_lines
goto :eof

:more_lines
set /a cnt=%cnt%+1 > nul
set /a delta=0x0%2-%skip% > nul
set /a skip=0x0%2 > nul
if %delta%<=1 goto :eof
if %delta%<=90 call :do_lines %2 || goto :eof
shift
if %cnt%<=4 goto :more_lines
goto :eof



:F03
:only_to show
#-#+ F03 - only_to_show example third function
#-# this function does nothing
#-# but has some description
goto :eof


#106 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 27 August 2021 - 08:42 PM

:ph34r: Very nice, absolutely a masterpiece. :magic:

 

I do not understand what's against an export-table? For instance 32-bit Windows-DLL's always give exports (and imports).

 

The ordinal's (not real ordinals !?) are a good idea. Only they are not there yet, but your format 'if %@retval%>=4 set /A skip=0x0%1-5-6 > nul' is mandatory. How to proceed?

 

Further I do not understand following sentence: 'The %var:~3% would need to be integrated by something *like* if %var:~0,1%.==+. set var=%var:~1%'

 

I had a few problems using your second version of SHOWFUNC.G4B. It it took me a long time and many changed versions to get better results.

 

Current limitations/ problems

1) Your ordinals are in fact function-abbrevations, but cannot be numbers (under 100).

2) If a (part of a) name of a function is mentioned somewhere in another '#-#'-remark-line on another position, I got sometimes Error 30.

3) Functions which names are an extension of an earlier (shorter) function-name are listed too, if the shorter name is given (maybe what you wanted?)

4) Length of function-name max 15 chars (max is a 32-chars label)

 

With following changes 'limitations/ problems 1+2' are okay and 'limitation 4' is max 16 chars now (every change is commented). Bonus included

!BAT
#-#+ 000 - showfunc.g4b v0.2 to view lines in .lll's marked with the # - # sequence
#showfunc.g4b v0.2 to view lines in .lll's marked with the # - # sequence
#-# (without spaces), 
#-# i.e. containing information about contained functions and parameters
#-# parameters: <target file> [<function name>]|[+]
#-# the sequence must be followed by a space
#-# the optional + means "show list of functions in the file"
setlocal
set target=%~f1
set locate=%2
set /a cnt=1 >nul
set /a skip=0 > nul
if %2.==. goto :no_params
if %2.==+. goto :param+
if %locate%==0 goto :eof :: Ordinal number 000 only placeholder
cat --locatei=%locate% %target% | call :do_single
#cat --locatei=" %locate%" %target% | call :do_single :: space is not needed, limits %locate% to 15 chars
goto :eof

:no_params
set locate=\x23\x2D\x23
cat --skip=%skip% --locate=%locate% %target% | call :do_lines
#cat --skip=%skip% --locatei="%locate%" %target% | call :do_lines :: locatei and double quotes not needed
goto :eof 

:param+
set locate=\x23\x2D\x23\x2B
cat --locate=%locate% %target% | call :do_lines
#cat --skip=%skip% --locatei="%locate%" %target% | call :do_lines :: locatei and double quotes not needed
goto :eof 

:F01
:do_lines
#-#+ F01 - do_lines subroutine to show informational lines
#-# parameters are the output of a cat --locate command
cat --skip=0x0%1 %target% | set thisline=
if %thisline:~0,3%==#-# && if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3%
#if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3% :: still extra echos if %locate% exists in other lines
shift
if not %1.==. goto :do_lines
goto :eof

:F02
:do_single
#-#+ F02 - do_single subroutine to show informational lines of a single function
#-# parameters are the output of a cat --locate command
#-# but a (valid) function name or number
#-# must have been passed to the command line
#call Fn.12 %locate% :: Fn.12 doesn't count preceding zero's!
set locate=%locate%
if %@retval%==3 set /A skip=0x0%1-5 > nul
call Fn.12 %locate%
if %@retval%>=4 set /A skip=0x0%1-5-6 > nul
cat --skip=%skip% %target% | set thisline=
#if not %thisline:~0,3%==#-# set thisline= :: Error 30 in some cases!
#if not "%thisline:~0,3%"=="#-#" set thisline= :: No Error 30
if %thisline:~0,3%==#-# && if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3%
#if %thisline:~3,1%==+ echo $[0x0F]%thisline:~4% || echo -e \t%thisline:~3% :: still extra echos if %locate% exists in other lines
shift
if not %1.==. goto :do_single
set locate=\x23\x2D\x23
cat --skip=%skip% --locate=%locate% %target% | call :more_lines
#cat --skip=%skip% --locatei="%locate%" %target% | call :more_lines :: locatei and double quotes not needed
goto :eof

:more_lines
set /a cnt=%cnt%+1 > nul
set /a delta=0x0%2-%skip% > nul
set /a skip=0x0%2 > nul
if %delta%<=1 goto :eof
if %delta%<=90 call :do_lines %2 || goto :eof
shift
if %cnt%<=4 goto :more_lines
goto :eof

:F03
:only_to show
#-#+ F03 - only_to_show example third function
#-# this function does nothing
#-# but has some description
goto :eof

BTW: Some (identical) changes are only byte-saving, not essential.

BTW2: First five lines will be shown with file-name as argument, thanks to '000 -' in '#-#+ 000 - showfunc.g4b v0.2 to view lines in .lll's marked with the # - # sequence'

BTW3: placeholder '000 - ' (6 chars including spaces) can be used for functions not having an ordinal yet.

BTW4: What I call 'numbers' must have three digits. Or with leading zero's, or from 100 upwards.  :ph34r: In the last case Fn.12 should work again.



#107 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 August 2021 - 09:02 AM

Well, the "number" is not really an issue :unsure:

call Fn.12 012

returns 2

but

call Fn.12 "012"

returns 3

just fine.

 

With the leading F the argument is treated as string and Fn.12 works fine even without the double quotes.

 

But it is better to use them, as I recently demonstrated by being "sloppy":

http://reboot.pro/in...showtopic=22551

 

I put tentatively the F prefix because it is easy to understand that is an abbreviation for Function and because I have not tested/exploredf the possibility of pure numerical labels. 

 

Anyway if we keep the F+2 numbers we have 100 functions available, (00 to 99) in a single .lll and if the limit for a .lll (which is a differently named .g4b) remains at 2000 lines, that is 20 lines per function (including labels and comments) on average, I doubt that a "same topic"  .lll will actually be ever filled with more than 100 functions. :dubbio:

 

But nothing prevents us (apart a single byte "wasted") to have F000 to F999, one whole thousand possible functions in a .lll.

 

the #3):

3) Functions which names are an extension of an earlier (shorter) function-name are listed too, if the shorter name is given (maybe what you wanted?)

 is a side effect (originally unintentional) but it is IMHO a good thing, as one may remember vaguely the function name and this way also similarly named ones are shown.

 

:duff:

Wonko



#108 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 30 August 2021 - 10:38 PM

I put tentatively the F prefix because it is easy to understand that is an abbreviation for Function and because I have not tested/exploredf the possibility of pure numerical labels. 

 

Anyway if we keep the F+2 numbers we have 100 functions available, (00 to 99) in a single .lll and if the limit for a .lll (which is a differently named .g4b) remains at 2000 lines, that is 20 lines per function (including labels and comments) on average, I doubt that a "same topic"  .lll will actually be ever filled with more than 100 functions. :dubbio:

 

But nothing prevents us (apart a single byte "wasted") to have F000 to F999, one whole thousand possible functions in a .lll.

 

'F' as prefix sounds logical (although I didn't make the association). Given max 128 labels higher numbers will be not possible.

 

I still found it a bit early to 'set' a format for numbered functions already. Also your format 'if %@retval%>=4 set /A skip=0x0%1-5-6 > nul' is 'one size fits all'.

 

I played a bit with SHOWFUNC.G4B to see if it can be made a little bit less restrictive, without losing functionality.

 

The two remark-types: '#-#+' and '#-#' are very powerful search indexes, together with a space before the searched phrase. I believe they are 'high potentials', together with your loops for ':more_lines/ :do_lines'.

 

Only the six reserved chars before a function-name are not necessary in my opinion. Enough is if search is 'near' with a range of six chars.

 

I tried this with following lines in call :do_single (lines original, or changed in my last post in Italic Bold):

 

(...)

if %skip%<=0 && set /A skip=0 > nul

set skip1=

cat --skip=%skip% --locate=\x23\x2D\x23\x2B --length=10 %target% > nul &; set /A skip1=%?% > nul

if exist skip1 && set skip=%skip1%

cat --skip=%skip% %target% | set thisline=

if not exist skip1 && set thisline=

if %thisline:~0,4%==#-#+ && echo $[0x0F]%thisline:~4%
#if %thisline:~0,3%==#-# &; if %thisline:~3,1%==+ && echo $[0x0F]%thisline:~4% ! echo -e \x20\x20\x20%thisline:~3%

(...)
 

With these changes it's possible to have more variety, see for instance this 'print-screen' (converted with Tesseract from a 640x480 Vbox print-screen):

grub> showfunZ GETLEAP.LLL +
GETLEAP LLL v0.5 (20210822), by deomsh.
FO1 - GetLeapYear <yyyy>
GetLeapSecond <yyyy> [<mm>1
002 Alias of: GetLeapSecond - Arguments: <yyyy> [<mm>1
3 GetLeapSecondCum <yyyy>
grub>
grub> showfund GETLEAP.LLL GETLEAP.LLL
GETLEAP.LLL v0.5 (20210822), by deomsh.
Exports: GetLeapYear GetLeapSecond GetLeapSecondCum
Import:
Mandatory Arguments: year in yyyy-format
grub> showfunZ GETLEAP.LLL GetLeapYear
FO1 - GetLeapYear <yyyy>
Remarks: Leap-years corrected for centuries and millenniums
grub> showfun2 GETLEAP.LLL FO1
FO1 - GetLeapYear <yyyy>
Remarks: Leap-years corrected for centuries and millenniums
grub> showfunZ GETLEAP.LLL GetLeapSecond
GetLeapSecond <yyyy> [<mm>1
Alias: 002
Optional Arguments: <mm> only with GetLeapSecond (some years from July
Remarks: Leap-seconds: in database known until juli 2021
grub> showfunZ GETLEAP.LLL 002
002 Alias of: GetLeapSecond - Arguments: <yyyy> [<mm>1
Optional Arguments: <mm> only with GetLeapSecond (some years from July
Remarks: Leap-seconds: in database known until juli 2021
grub> showfun2 GETLEAP.LLL GetLeapSecondCum
grub> showfunZ GETLEAP.LLL 3
3 GetLeapSecondCum <yyyy>
Remarks: Leap-seconds: in database known until juli 2021
yrub> 

BTW Intentionally I made no corrections, except removing empty lines added by Tesseract.

 

the #3):

3) Functions which names are an extension of an earlier (shorter) function-name are listed too, if the shorter name is given (maybe what you wanted?)

 is a side effect (originally unintentional) but it is IMHO a good thing, as one may remember vaguely the function name and this way also similarly named ones are shown.

 

I agree, only I found that call :more_lines came only after the last function found, so lines with '#-#' after a function-name/ number/ F-abbreviation are not showed.

 

This I tackled in following way: just set the call earlier (with some minor changes)

 

set locatemo=\x23\x2D\x23\x20

if %thisline:~0,4%==#-#+ && set /a cnt=1 > nul && cat --skip=%skip% --locate=%locatemo% %target% | call :more_lines
shift
if not %1.==. goto :do_single

#set locate=\x23\x2D\x23
#cat --skip=%skip% --locate=%locate% %target% | call :more_lines

 

Output for instance this 'print-screen' (converted with https://image2text.site also from a 640x480 Vbox print-screen):

grub> showfun2 GETLEAP.LLL GetLeap all
GETLEAP. LLL vO.5 (20210822), by deomsh.
Exports: GetLeapYear GetLeapSecond GetLeapSecondCum
Imports:
Mandatory Arguments: year in yyyy-format
F01 - GetLeapYear <yyyy>
Remarks: Leap-years corrected for centuries and millenniums
GetLeapSecond <yyyy> [<mm>]
Alias: 002
Optional Arguments: <mm> only with GetLeapSecond (some years from July, 1)
Remarks: Leap-seconds: in database known until juli 2021
3 GetLeapSecondCum <yyyy>
Remarks: Leap-seconds: in database known until juli 2021
grub> showfun2 GETLEAP.LLL GetLeapSecond find
GetLeapSecond <yyyy> [<mm>]
Alias: 002
Optional Arguments: <mm> only with GetLeapSecond (some years from July, 1)
Remarks: Leap-seconds: in database known until juli 2021
3 GetLeapSecondCum <yyyy>
Remarks: Leap-seconds: in database known until juli 2021
grub> showfun2 GETLEAP.LLL GetLeapSecondC search
3 GetLeapSecondCum <yyyy>
Remarks: Leap-seconds: in database known until juli 2021
grub>

BTW Intentionally I made no corrections ('O' vs '0' / to many spaces)

BTW2 still no time to try Wonko´s tip: using the serial console of grub4dos in Virtualbox via Putty
BTW3 For single function-search I added a space AFTER variable %locate% too (so max 14 real chars left). To search with first part of function-name I added a switch (for the forget-full: three phrases possible).

 

if not /i %3==all if not /i %3==find if not /i %3==search && if not %ordinal%==Y && set locate=%locate%\x20

 

Oeps, no '--' or '/' before, :ph34r: I like '/' most (fastest for me).



#109 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 31 August 2021 - 08:35 AM

Very good. :)

I love it when a plan comes together :smiling9:

Spoiler


It seems to me that you rounded most if not all the sharp edges.

I did not remember the 128 labels limit, if each function will use two of them (Fxx + actual function name) that will make max 64 functions per .lll file, in practice many less because of sub-routines and loops. :(

It might be need to add a "translation" function to the ordinal calls, to mantain the possibility (theoretical) of around 100 functions.

I mean, right now you can call by function as:
call /xxxyyy.lll :mynicefunction
or
call /xxxyyy.lll :F05
what if we have:
#:F05
:mynicefunction
we could
call /xxxyyy.lll #:F05
and have at the start something (loosely) *like*

set param=%1
if "%param:~0,1%"=="#" cat --locate="%param%" %~f0 | set where=
set /A where=0x%where%+7
cat --skip=%where% --length=80 | set fname=
set param=%fname%

... just saying ... :unsure:

:duff:
Wonko



#110 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 02 September 2021 - 11:36 PM

Thanks! I was not fully sure if you would appreciate my efforts changing your script. :unsure:

 

About the SHOWFUNC.G4B: only value of 'delta' is a bit low with my changes: for instance in these lines:

 

#-#+ LoadLibrary [<filename alias>]
#-# Alias: 1
#-#+ 1 Alias of: LoadLibrary [<filename alias>]
#-# Load Library with insmod

 

only not all #-# lines are echod if LoadLibrary is searched (second #-#+ is skipped, and should be!). I think a delta-value of 2 x 80 + 4 for EOL will give no troubles, unless extremely short calls are used.

 

About the 'ordinals': I tested your idea of searching with some remark before. My edit-line file is very big, more than 140 KB now. Just above the last label I inserted #-#:F00 (personally I use #: for temporarily remarking a whole sub-routine).

 

Further I also tried following approach:

debug msg=0
set locate=%~1
checkrange 0:999 calc %locate% > nul && set ordinal=Y
if not %ordinal%==Y && checkrange 0:99 calc %locate:~1% > nul && set ordinal=Y
if not %ordinal%==Y && call :%~1 %* &; goto :end
checkrange 0:99 calc %locate:~0,1% > nul || set locate=%locate:~1%
set ordinal=
if %locate%>=90 &; if %locate%==90 && call :Function90 %* ! if %locate%==91 && call :Function91 %* ! if %locate%==92 && call :Function92 %* ! if %locate%==93 && call :Function93 %* ! if %locate%==94 && call :Function94 %* ! if %locate%==95 && call :Function95 %* ! if %locate%==96 && call :Function96 %* ! if %locate%==97 && call :Function97 %* ! if %locate%==98 && call :Function98 %* ! if %locate%==99 && call :Function99 %*
if %locate%>=90 && goto :end
(.....)
if %locate%>=00 &; if %locate%==00 && call :Help %* ! if %locate%==01 && call :CntLabel %* ! if %locate%==02 && call :CntNumLabel %* ! if %locate%==03 && call :CntRemark %* ! if %locate%==04 && call :CntRemarkLine %* ! if %locate%==05 && call :CntRemarkLine15 %* ! if %locate%==06 && call :Function06 %* ! if %locate%==07 && call :Function07 %* ! if %locate%==08 && call :Function08 %* ! if %locate%==09 && call :Function09 %*
:end
#echo Function: %~1 result=%result%
debug msg=3
goto :eof 

:Function09
set result=%0
goto :eof
(....)

BTW: I started with highest function-numbers, maybe better with lowest and '<='

BTW2: extra if-statements: 3 up to 30.

 

I did some looptests in VBox how fast searching is in a bigger file on disk, but doesn't seem so good (explanation below):

grub> ordinal2.g4b CntRemark /fattext.g4b "#-#F00" ;; set r
result=0
grub> ordinal2.g4b CntRemark /fattext.g 4b "#-#:F00" ; set r
result=1
grub>
grub> looptest insmod num:100 VARS:dummy;result ECHOTICKS POST.G4B
Testtime: 0.0000 seconds / 100 tests  <-:-> Bias: 12.9 ms tickpsec=3395
grub>
grub> (hd0,0)/looptest.g4b ordinal2.g4b CntRemark /fattext.g4b "#-#:F00" ;; se>
Testtime: 11.3067 seconds / 100 tests
result=1
grub>
grub> dd if=(hd0,0)/fattext.g4b of =(md)0x19000+288 > nul
grub> (hd0,0)/looptest.g4b ordinal2.g4b CntRemark (md)0x19000+511 "#-#:F00" ;;>
Testtime: 0.5331 seconds / 100 tests
result=1
grub>
grub> (hd0,0)/looptest.g4b ordinal2.g4b F09 ; set r
Testtime: 0.1036 seconds / 100 tests
result=:Function09
grub>
grub> (hd0,0)/looptest.g4b delmod ordinal2.g4b F09 ; set r
Testtime: 3.5856 seconds / 100 tests
result=:Function09
grub>

Line 1-2: #-#F00 not found with function CntRemark

Line 3-4: #-#:F00 found!

Line 6-7: adjustment of looptest.g4b.

Line 9-11: 100 searches take a long time :(

Line 13-16: better if file is loaded in memory. Load time with dd is NOT counted.

Line 18-20: using if-statements still five times faster (but 'traveling' to label far away not counted - as far as I remember:  very fast)

Line 22-24: but loading file ordinal2.g4b with insmod: need-for-speed

 

BTW: technical detail: smallest unit of 'time' in this looptest in VBOX is about 1/3300 sec, so four digits are not possible (like on real hardware with 'ticks' of 12000 up to 25000). See line 7.
 

 

 



#111 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 September 2021 - 08:56 AM

Yes, using memory (either as the hosting drive for the batch(es) or having the script loaded as module) might be game-changing, I am having the same (or similar) issue here:

http://reboot.pro/in...showtopic=22553

 

(and as said there I already had it at the time of mbrview)

 

The dd (with a suitable blocksize) or the map --mem is usually (IMHO) of "minor" relevance in practice, if we consider it "booting time".

 

Given that the map --mem works very fine with gzipped files, it may be worth to make it "standard practice" to have grub4dos scripts in a (gzipped) floppy image and map it to memory at boot time. :unsure:

 

About the "delta" value, as I see it *whatever* value works will do nicely :).

 

:duff:

Wonko







Also tagged with one or more of these keywords: grub4dos

5 user(s) are reading this topic

0 members, 5 guests, 0 anonymous users