Jump to content

- - - - -

Writing to the Grub4dos' keyboard buffer possible?


  • Please log in to reply
77 replies to this topic

#76 deomsh



  • Members
  • 46 posts

Posted A week ago

The board is set for giving limited capabilities to posters will less than 50 posts (this is because of spammers editing previous posts to add links to crappy sites), you are near to reach that number of posts, from then on you will have no more time limits on editing previous posts.

Thanks a lot, now this is clear to me.


The %* is ALL parameters excluded the %0 one.


In batch you have the shift command to manipulate parameter numbers/order, but the grub4dos implementation does not accept shift -1 if I recall correctly (not that it is usually needed).

Good to know about %*.


What I do not like so much about using shift in the main routine is losing arguments (with regard to in this 'function'-project). And if there are many arguments, it is a waste of variables, needed to hold the values of the arguments.


In one of my projects I was because of this *thing* condemned to endless debugging with varsleft.g4b (I believe it's from steve6375 - no author 'inside'. It's a very handy debugging-tool).


I experimented with call :%1 %* - seems to give no problems, I only have to test if shift inside a sub-routine does the same, without losing anything in the main routine.


I have been thinking about the dll-'idea' I should 'not attribute' to you.

To give this sort of call's a more unified structure, should their not be error-handling too? Although I have only vague notions of, for instance, the windows API, I know many different error-codes are needed.


To exemplify I made a function I really need: counting number of labels. My latest count (105 labels) took me a very long time, and I was not even sure about the final number. So I made the function 'cntlabel'. Still not very high-level, just meant to give an idea about a possible general structure.

#FUNCTION.G4B by deomsh; thanks to Wonko the Sane
#DLL for Grub4Dos
#Arguments: function, mandatory arguments, optional arguments; errormsg: 0=No function given, 1=Function not supported
#Implemented: cntlabel (20210717)
debug off
setlocal && set *
if "%~1"=="" && set /a errormsg=0 > nul
if not exist errormsg && call :dbfunc %~1
if not exist errormsg && call :%~1 %*
endlocal && set result=%result% && set errormsg=%errormsg%
echo %1: result=%result% errormsg=%errormsg%
goto :eof

:cntlabel #Function: count number of labels; Argument: FILE; Optional: dos or mac; errormsg: 2=FILE not given, 3=FILE does not exist
setlocal && set *
if "%~2"=="" && endlocal && set /a errormsg=2 > nul && goto :eof
if not exist %~2 && endlocal && set /a errormsg=3 > nul && goto :eof
if /i "%~3"=="dos" && set EOL=\x0D\x0A ! set EOL=\x0A
if /i "%~3"=="mac" && set EOL=\x0D
echo EOL=%EOL%
cat --locate=%EOL%\x3A %~2 > nul &; set /a result=%@retval% > nul
endlocal && set result=%result%
goto :eof

:dbfunc #database of available functions
setlocal && set *
if not /i %~1==cntlabel && endlocal && set /a errormsg=1 > nul && goto :eof
goto :eof

This is the 'print-screen' of the output (the optional argument gives also more possible uses of cntlabel):

grub> (hd0,0)/function.g4b
: result: errormsg=0 
grub> (hd0,00/function.g4b cntlabe 
cntlabe: result= errormsg=1 
grub> (hd0,0)/function.g4b cntlabel (hd0,0)/fattext.g4d
cntlabel: result= errormsg=3 
grub> (hd0,0)/function.g4b cntlabel (hd0,0)/fattext.g4b 
cntlabel: result=102 errormsg= 
grub> (hd0,0)/function.g4b cntlabel (hd0,0)/fattext.g4b dos 
cntlabel: result=102 errormsg= 
grub> (hd0,0)/function.g4b cntlabel (hd0,0)/fattext.g4b mac 
cntlabel: result= errormsg= 
grub> (hd0,0)/function.g4b cntlabel (hd0,0)/fattext.g4b ms-dos 
cntlabel: result=102 errormsg= 

BTW I tried to make textual error messages too, but today I was plagued again by Error 16 Inconsistent filesystem structure. Has something to do with editing files in Windows in combination with Imdisk to have access to VBox in combination with 'saving' grub4dos-sessions in VBox. After 'refreshing everything' Error 16 disappeared.


What do you think about error-handling?

#77 deomsh



  • Members
  • 46 posts

Posted A week ago

Edit 'print-screen':

OCR was bad this time, my eyes too. The echo of the three last EOL-codes should have been the following ones:




Edited by deomsh, A week ago.

#78 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 5 days ago

Every time you use call or invoke a file with parameters, it is a different stack of % parameters.

Using shift in "main" will shift the "main" ones, if you use shift in a subroutine it will shift the "call" parameters.

No problem there.


About error checking/handling, it could be a nice feature, but (IMHO) not needed and actually overkill in the specific case of "dividing" a large batch in a "main program"+"functions library".


I mean - unlke the mathfunc.g4b (lousy) example, the idea of a .lll file is that it is "never" called from command line, but only by programs, so it is the program Author that is responsible for calling the library (rectius the function in it) with the correct parameters.


If the idea is that of using these functions from command line, it would still make sense to have an intermediate level (not entirely unlike the rundll32.exe) that takes care of validating the user input/parameters and echo result(s) in a suitable format.




  • deomsh likes this

Also tagged with one or more of these keywords: grub4dos

5 user(s) are reading this topic

0 members, 5 guests, 0 anonymous users