diff options
author | dteske <dteske@FreeBSD.org> | 2012-11-06 19:26:36 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-11-06 19:26:36 +0000 |
commit | 76b008123e94513a6df71a4377ffffcc6a62567f (patch) | |
tree | 60586d2ed15f7b544fd7bcefab8f26e751869b7f /sys/boot/forth | |
parent | 451c63e7275b9146f36d3e3e350d226eb8ccdc8e (diff) | |
download | FreeBSD-src-76b008123e94513a6df71a4377ffffcc6a62567f.zip FreeBSD-src-76b008123e94513a6df71a4377ffffcc6a62567f.tar.gz |
Add ontop of my existing boot loader Forth code, including support for
submenus. See menusets.4th(8) for additional details including examples.
Discussed on arch and recommended for inclusion at the devsummit.
This change does not alter the appearance or user experience, only enhances
possibilities.
Reviewed by: adrian (co-mentor)
Approved by: adrian (co-mentor)
Diffstat (limited to 'sys/boot/forth')
-rw-r--r-- | sys/boot/forth/loader.4th | 6 | ||||
-rw-r--r-- | sys/boot/forth/menu-commands.4th | 9 | ||||
-rw-r--r-- | sys/boot/forth/menu.4th | 21 | ||||
-rw-r--r-- | sys/boot/forth/menusets.4th | 610 | ||||
-rw-r--r-- | sys/boot/forth/menusets.4th.8 | 372 |
5 files changed, 1016 insertions, 2 deletions
diff --git a/sys/boot/forth/loader.4th b/sys/boot/forth/loader.4th index e252cfe..c701b3c 100644 --- a/sys/boot/forth/loader.4th +++ b/sys/boot/forth/loader.4th @@ -60,6 +60,12 @@ only forth also support-functions also builtins definitions else drop then + s" menusets-unset" + sfind if + execute + else + drop + then ; : boot diff --git a/sys/boot/forth/menu-commands.4th b/sys/boot/forth/menu-commands.4th index 4dba8b3..5c76769 100644 --- a/sys/boot/forth/menu-commands.4th +++ b/sys/boot/forth/menu-commands.4th @@ -26,6 +26,8 @@ marker task-menu-commands.4th +include /boot/menusets.4th + variable kernel_state variable root_state @@ -223,3 +225,10 @@ variable root_state TRUE \ loop menu again ; + +: goto_menu ( N M -- N TRUE ) + menu-unset + menuset-loadsetnum ( n m -- n ) + menu-redraw + TRUE \ Loop menu again +; diff --git a/sys/boot/forth/menu.4th b/sys/boot/forth/menu.4th index f39131d..7d3de94 100644 --- a/sys/boot/forth/menu.4th +++ b/sys/boot/forth/menu.4th @@ -493,6 +493,10 @@ create init_text8 255 allot \ Initialize "Reboot" menu state variable (prevents double-entry) false menurebootadded ! + menu_start + 1- menuidx ! \ Initialize the starting index for the menu + 0 menurow ! \ Initialize the starting position for the menu + 49 \ Iterator start (loop range 49 to 56; ASCII '1' to '8') begin \ If the "Options:" separator, print it. @@ -841,6 +845,8 @@ create init_text8 255 allot exit ( pedantic; never reached ) then + dup menureboot @ = if 0 reboot then + \ Evaluate the decimal ASCII value against known menu item \ key associations and act accordingly @@ -932,8 +938,7 @@ create init_text8 255 allot \ continue if less than 57 until drop \ loop iterator - - menureboot @ = if 0 reboot then + drop \ key pressed again \ Non-operational key was pressed; repeat ; @@ -1005,6 +1010,18 @@ create init_text8 255 allot -rot 2dup 12 + c! rot \ replace 'N' evaluate + s" 0 toggle_stateN !" \ used by toggle_menuitem + -rot 2dup 14 + c! rot \ replace 'N' + evaluate + + s" 0 cycle_stateN !" \ used by cycle_menuitem + -rot 2dup 13 + c! rot \ replace 'N' + evaluate + + s" 0 init_textN c!" \ used by toggle_menuitem + -rot 2dup 11 + c! rot \ replace 'N' + evaluate + 1+ dup 56 > \ increment, continue if less than 57 until drop \ iterator diff --git a/sys/boot/forth/menusets.4th b/sys/boot/forth/menusets.4th new file mode 100644 index 0000000..9bf859a --- /dev/null +++ b/sys/boot/forth/menusets.4th @@ -0,0 +1,610 @@ +\ Copyright (c) 2012 Devin Teske <dteske@FreeBSD.org> +\ All rights reserved. +\ +\ Redistribution and use in source and binary forms, with or without +\ modification, are permitted provided that the following conditions +\ are met: +\ 1. Redistributions of source code must retain the above copyright +\ notice, this list of conditions and the following disclaimer. +\ 2. Redistributions in binary form must reproduce the above copyright +\ notice, this list of conditions and the following disclaimer in the +\ documentation and/or other materials provided with the distribution. +\ +\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +\ SUCH DAMAGE. +\ +\ $FreeBSD$ + +marker task-menusets.4th + +variable menuset_use_name + +create menuset_affixbuf 255 allot +create menuset_x 1 allot +create menuset_y 1 allot + +: menuset-loadvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + s" set cmdbuf='set ${type}_${var}=\$'" evaluate + s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length + menuset_use_name @ true = if + s" set cmdbuf=${cmdbuf}${affix}${type}_${var}" + ( u1 -- u1 c-addr2 u2 ) + else + s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}" + ( u1 -- u1 c-addr2 u2 ) + then + evaluate ( u1 c-addr2 u2 -- u1 ) + s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) + rot 2 pick 2 pick over + -rot + tuck - + ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) + \ Generate a string representing rvalue inheritance var + getenv dup -1 = if + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) + \ NOT set -- clean up the stack + drop ( c-addr2 u2 -1 -- c-addr2 u2 ) + 2drop ( c-addr2 u2 -- ) + else + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) + \ SET -- execute cmdbuf (c-addr2/u2) to inherit value + 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) + evaluate ( c-addr2 u2 -- ) + then + + s" cmdbuf" unsetenv +; + +: menuset-unloadvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + menuset_use_name @ true = if + s" set buf=${affix}${type}_${var}" + else + s" set buf=${type}set${affix}_${var}" + then + evaluate + s" buf" getenv unsetenv + s" buf" unsetenv +; + +: menuset-loadmenuvar ( -- ) + s" set type=menu" evaluate + menuset-loadvar +; + +: menuset-unloadmenuvar ( -- ) + s" set type=menu" evaluate + menuset-unloadvar +; + +: menuset-loadxvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $x is "1" through "8" + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + s" set cmdbuf='set ${type}_${var}[${x}]=\$'" evaluate + s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length + menuset_use_name @ true = if + s" set cmdbuf=${cmdbuf}${affix}${type}_${var}[${x}]" + ( u1 -- u1 c-addr2 u2 ) + else + s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}[${x}]" + ( u1 -- u1 c-addr2 u2 ) + then + evaluate ( u1 c-addr2 u2 -- u1 ) + s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) + rot 2 pick 2 pick over + -rot + tuck - + ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) + \ Generate a string representing rvalue inheritance var + getenv dup -1 = if + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) + \ NOT set -- clean up the stack + drop ( c-addr2 u2 -1 -- c-addr2 u2 ) + 2drop ( c-addr2 u2 -- ) + else + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) + \ SET -- execute cmdbuf (c-addr2/u2) to inherit value + 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) + evaluate ( c-addr2 u2 -- ) + then + + s" cmdbuf" unsetenv +; + +: menuset-unloadxvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $x is "1" through "8" + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + menuset_use_name @ true = if + s" set buf=${affix}${type}_${var}[${x}]" + else + s" set buf=${type}set${affix}_${var}[${x}]" + then + evaluate + s" buf" getenv unsetenv + s" buf" unsetenv +; + +: menuset-loadansixvar ( -- ) + s" set type=ansi" evaluate + menuset-loadxvar +; + +: menuset-unloadansixvar ( -- ) + s" set type=ansi" evaluate + menuset-unloadxvar +; + +: menuset-loadmenuxvar ( -- ) + s" set type=menu" evaluate + menuset-loadxvar +; + +: menuset-unloadmenuxvar ( -- ) + s" set type=menu" evaluate + menuset-unloadxvar +; + +: menuset-loadtoggledxvar ( -- ) + s" set type=toggled" evaluate + menuset-loadxvar +; + +: menuset-unloadtoggledxvar ( -- ) + s" set type=toggled" evaluate + menuset-unloadxvar +; + +: menuset-loadxyvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $x is "1" through "8" + \ $y is "0" through "9" + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + s" set cmdbuf='set ${type}_${var}[${x}][${y}]=\$'" evaluate + s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length + menuset_use_name @ true = if + s" set cmdbuf=${cmdbuf}${affix}${type}_${var}[${x}][${y}]" + ( u1 -- u1 c-addr2 u2 ) + else + s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}[${x}][${y}]" + ( u1 -- u1 c-addr2 u2 ) + then + evaluate ( u1 c-addr2 u2 -- u1 ) + s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) + rot 2 pick 2 pick over + -rot + tuck - + ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) + \ Generate a string representing rvalue inheritance var + getenv dup -1 = if + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) + \ NOT set -- clean up the stack + drop ( c-addr2 u2 -1 -- c-addr2 u2 ) + 2drop ( c-addr2 u2 -- ) + else + ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) + \ SET -- execute cmdbuf (c-addr2/u2) to inherit value + 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) + evaluate ( c-addr2 u2 -- ) + then + + s" cmdbuf" unsetenv +; + +: menuset-unloadxyvar ( -- ) + + \ menuset_use_name is true or false + \ $type should be set to one of: + \ menu toggled ansi + \ $var should be set to one of: + \ caption command keycode text ... + \ $x is "1" through "8" + \ $y is "0" through "9" + \ $affix is either prefix (menuset_use_name is true) + \ or infix (menuset_use_name is false) + + menuset_use_name @ true = if + s" set buf=${affix}${type}_${var}[${x}][${y}]" + else + s" set buf=${type}set${affix}_${var}[${x}][${y}]" + then + evaluate + s" buf" getenv unsetenv + s" buf" unsetenv +; + +: menuset-loadansixyvar ( -- ) + s" set type=ansi" evaluate + menuset-loadxyvar +; + +: menuset-unloadansixyvar ( -- ) + s" set type=ansi" evaluate + menuset-unloadxyvar +; + +: menuset-loadmenuxyvar ( -- ) + s" set type=menu" evaluate + menuset-loadxyvar +; + +: menuset-unloadmenuxyvar ( -- ) + s" set type=menu" evaluate + menuset-unloadxyvar +; + +: menuset-setnum-namevar ( N -- C-Addr/U ) + + s" menuset_nameNNNNN" ( n -- n c-addr1 u1 ) \ variable basename + drop 12 ( n c-addr1 u1 -- n c-addr1 12 ) \ remove "NNNNN" + rot ( n c-addr1 12 -- c-addr1 12 n ) \ move number on top + + \ convert to string + s>d <# #s #> ( c-addr1 12 n -- c-addr1 12 c-addr2 u2 ) + + \ Combine strings + begin ( using u2 in c-addr2/u2 pair as countdown to zero ) + over ( c-addr1 u1 c-addr2 u2 -- continued below ) + ( c-addr1 u1 c-addr2 u2 c-addr2 ) \ copy src-addr + c@ ( c-addr1 u1 c-addr2 u2 c-addr2 -- continued below ) + ( c-addr1 u1 c-addr2 u2 c ) \ get next src-addr byte + 4 pick 4 pick + ( c-addr1 u1 c-addr2 u2 c -- continued below ) + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 ) + \ get destination c-addr1/u1 pair + + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 -- cont. below ) + ( c-addr1 u1 c-addr2 u2 c c-addr3 ) + \ combine dest-c-addr to get dest-addr for byte + c! ( c-addr1 u1 c-addr2 u2 c c-addr3 -- continued below ) + ( c-addr1 u1 c-addr2 u2 ) + \ store the current src-addr byte into dest-addr + + 2swap 1+ 2swap \ increment u1 in destination c-addr1/u1 pair + swap 1+ swap \ increment c-addr2 in source c-addr2/u2 pair + 1- \ decrement u2 in the source c-addr2/u2 pair + + dup 0= \ time to break? + until + + 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 ) + \ drop temporary number-format conversion c-addr2/u2 +; + +: menuset-checksetnum ( N -- ) + + \ + \ adjust input to be both positive and no-higher than 65535 + \ + abs dup 65535 > if drop 65535 then ( n -- n ) + + \ + \ The next few blocks will determine if we should use the default + \ methodology (referencing the original numeric stack-input), or if- + \ instead $menuset_name{N} has been defined wherein we would then + \ use the value thereof as the prefix to every menu variable. + \ + + false menuset_use_name ! \ assume name is not set + + menuset-setnum-namevar + \ + \ We now have a string that is the assembled variable name to check + \ for... $menuset_name{N}. Let's check for it. + \ + 2dup ( c-addr1 u1 -- c-addr1 u1 c-addr1 u1 ) \ save a copy + getenv dup -1 <> if ( c-addr1 u1 c-addr1 u1 -- c-addr1 u1 c-addr2 u2 ) + \ The variable is set. Let's clean up the stack leaving only + \ its value for later use. + + true menuset_use_name ! + 2swap 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr2 u2 ) + \ drop assembled variable name, leave the value + else ( c-addr1 u1 c-addr1 u1 -- c-addr1 u1 -1 ) \ no such variable + \ The variable is not set. Let's clean up the stack leaving the + \ string [portion] representing the original numeric input. + + drop ( c-addr1 u1 -1 -- c-addr1 u1 ) \ drop -1 result + 12 - swap 12 + swap ( c-addr1 u1 -- c-addr2 u2 ) + \ truncate to original numeric stack-input + then + + \ + \ Now, depending on whether $menuset_name{N} has been set, we have + \ either the value thereof to be used as a prefix to all menu_* + \ variables or we have a string representing the numeric stack-input + \ to be used as a "set{N}" infix to the same menu_* variables. + \ + \ For example, if the stack-input is 1 and menuset_name1 is NOT set + \ the following variables will be referenced: + \ ansiset1_caption[x] -> ansi_caption[x] + \ ansiset1_caption[x][y] -> ansi_caption[x][y] + \ menuset1_acpi -> menu_acpi + \ menuset1_caption[x] -> menu_caption[x] + \ menuset1_caption[x][y] -> menu_caption[x][y] + \ menuset1_command[x] -> menu_command[x] + \ menuset1_init -> ``evaluated'' + \ menuset1_init[x] -> menu_init[x] + \ menuset1_keycode[x] -> menu_keycode[x] + \ menuset1_options -> menu_options + \ menuset1_optionstext -> menu_optionstext + \ menuset1_reboot -> menu_reboot + \ toggledset1_ansi[x] -> toggled_ansi[x] + \ toggledset1_text[x] -> toggled_text[x] + \ otherwise, the following variables are referenced (where {name} + \ represents the value of $menuset_name1 (given 1 as stack-input): + \ {name}ansi_caption[x] -> ansi_caption[x] + \ {name}ansi_caption[x][y] -> ansi_caption[x][y] + \ {name}menu_acpi -> menu_acpi + \ {name}menu_caption[x] -> menu_caption[x] + \ {name}menu_caption[x][y] -> menu_caption[x][y] + \ {name}menu_command[x] -> menu_command[x] + \ {name}menu_init -> ``evaluated'' + \ {name}menu_init[x] -> menu_init[x] + \ {name}menu_keycode[x] -> menu_keycode[x] + \ {name}menu_options -> menu_options + \ {name}menu_optionstext -> menu_optionstext + \ {name}menu_reboot -> menu_reboot + \ {name}toggled_ansi[x] -> toggled_ansi[x] + \ {name}toggled_text[x] -> toggled_text[x] + \ + \ Note that menuset{N}_init and {name}menu_init are the initializers + \ for the entire menu (for wholly dynamic menus) opposed to the per- + \ menuitem initializers (with [x] afterward). The whole-menu init + \ routine is evaluated and not passed down to $menu_init (which + \ would result in double evaluation). By doing this, the initializer + \ can initialize the menuset before we transfer it to active-duty. + \ + + \ + \ Copy our affixation (prefix or infix depending on menuset_use_name) + \ to our buffer so that we can safely use the s-quote (s") buf again. + \ + menuset_affixbuf 0 2swap ( c-addr2 u2 -- c-addr1 0 c-addr2 u2 ) + begin ( using u2 in c-addr2/u2 pair as countdown to zero ) + over ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 c-addr2 u2 c-addr2 ) + c@ ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 c-addr2 u2 c ) + 4 pick 4 pick + ( c-addr1 u1 c-addr2 u2 c -- continued below ) + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 ) + + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 -- continued below ) + ( c-addr1 u1 c-addr2 u2 c c-addr3 ) + c! ( c-addr1 u1 c-addr2 u2 c c-addr3 -- continued below ) + ( c-addr1 u1 c-addr2 u2 ) + 2swap 1+ 2swap \ increment affixbuf byte position/count + swap 1+ swap \ increment strbuf pointer (source c-addr2) + 1- \ decrement strbuf byte count (source u2) + dup 0= \ time to break? + until + 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 ) \ drop strbuf c-addr2/u2 + + \ + \ Create a variable for referencing our affix data (prefix or infix + \ depending on menuset_use_name as described above). This variable will + \ be temporary and only used to simplify cmdbuf assembly. + \ + s" affix" setenv ( c-addr1 u1 -- ) +; + +: menuset-cleanup ( -- ) + s" type" unsetenv + s" var" unsetenv + s" x" unsetenv + s" y" unsetenv + s" affix" unsetenv +; + +: menuset-loadsetnum ( N -- ) + + menuset-checksetnum ( n -- ) + + \ + \ From here out, we use temporary environment variables to make + \ dealing with variable-length strings easier. + \ + \ menuset_use_name is true or false + \ $affix should be use appropriated w/respect to menuset_use_name + \ + + \ ... menu_init ... + s" set var=init" evaluate + menuset-loadmenuvar + + \ If menu_init was set by the above, evaluate it here-and-now + \ so that the remaining variables are influenced by its actions + s" menu_init" 2dup getenv dup -1 <> if + 2swap unsetenv \ don't want later menu-create to re-call this + evaluate + else + drop 2drop ( n c-addr u -1 -- n ) + then + + [char] 1 ( -- x ) \ Loop range ASCII '1' (49) to '8' (56) + begin + dup menuset_x tuck c! 1 s" x" setenv \ set loop iterator and $x + + s" set var=caption" evaluate + + \ ... menu_caption[x] ... + menuset-loadmenuxvar + + \ ... ansi_caption[x] ... + menuset-loadansixvar + + [char] 0 ( x -- x y ) \ Inner Loop ASCII '1' (48) to '9' (57) + begin + dup menuset_y tuck c! 1 s" y" setenv + \ set inner loop iterator and $y + + \ ... menu_caption[x][y] ... + menuset-loadmenuxyvar + + \ ... ansi_caption[x][y] ... + menuset-loadansixyvar + + 1+ dup 57 > ( x y -- y' 0|-1 ) \ increment and test + until + drop ( x y -- x ) + + \ ... menu_command[x] ... + s" set var=command" evaluate + menuset-loadmenuxvar + + \ ... menu_init[x] ... + s" set var=init" evaluate + menuset-loadmenuxvar + + \ ... menu_keycode[x] ... + s" set var=keycode" evaluate + menuset-loadmenuxvar + + \ ... toggled_text[x] ... + s" set var=text" evaluate + menuset-loadtoggledxvar + + \ ... toggled_ansi[x] ... + s" set var=ansi" evaluate + menuset-loadtoggledxvar + + 1+ dup 56 > ( x -- x' 0|-1 ) \ increment iterator + \ continue if less than 57 + until + drop ( x -- ) \ loop iterator + + \ ... menu_reboot ... + s" set var=reboot" evaluate + menuset-loadmenuvar + + \ ... menu_acpi ... + s" set var=acpi" evaluate + menuset-loadmenuvar + + \ ... menu_options ... + s" set var=options" evaluate + menuset-loadmenuvar + + \ ... menu_options ... + s" set var=optionstext" evaluate + menuset-loadmenuvar + + menuset-cleanup +; + +: menuset-loadinitial ( -- ) + s" menuset_initial" getenv dup -1 <> if + ?number 0<> if + menuset-loadsetnum + then + else + drop \ cruft + then +; + +: menusets-unset ( -- ) + + s" menuset_initial" unsetenv + + 1 begin + dup menuset-checksetnum ( n n -- n ) + + dup menuset-setnum-namevar ( n n -- n ) + unsetenv + + \ If the current menuset does not populate the first menuitem, + \ we stop completely. + + menuset_use_name @ true = if + s" set buf=${affix}menu_caption[1]" + else + s" set buf=menuset${affix}_caption[1]" + then + evaluate s" buf" getenv getenv -1 = if + drop ( n -- ) + s" buf" unsetenv + menuset-cleanup + exit + else + drop ( n c-addr2 -- n ) \ unused + then + + [char] 1 ( n -- n x ) \ Loop range ASCII '1' (49) to '8' (56) + begin + dup menuset_x tuck c! 1 s" x" setenv \ set $x to x + + s" set var=caption" evaluate + menuset-unloadmenuxvar + menuset-unloadmenuxvar + menuset-unloadansixvar + [char] 0 ( n x -- n x y ) \ Inner loop '0' to '9' + begin + dup menuset_y tuck c! 1 s" y" setenv + \ sets $y to y + menuset-unloadmenuxyvar + menuset-unloadansixyvar + 1+ dup 57 > ( n x y -- n x y' 0|-1 ) + until + drop ( n x y -- n x ) + s" set var=command" evaluate menuset-unloadmenuxvar + s" set var=init" evaluate menuset-unloadmenuxvar + s" set var=keycode" evaluate menuset-unloadmenuxvar + s" set var=text" evaluate menuset-unloadtoggledxvar + s" set var=ansi" evaluate menuset-unloadtoggledxvar + + 1+ dup 56 > ( x -- x' 0|-1 ) \ increment and test + until + drop ( n x -- n ) \ loop iterator + + s" set var=acpi" evaluate menuset-unloadmenuvar + s" set var=init" evaluate menuset-unloadmenuvar + s" set var=options" evaluate menuset-unloadmenuvar + s" set var=optionstext" evaluate menuset-unloadmenuvar + s" set var=reboot" evaluate menuset-unloadmenuvar + + 1+ dup 65535 > ( n -- n' 0|-1 ) \ increment and test + until + drop ( n' -- ) \ loop iterator + + s" buf" unsetenv + menuset-cleanup +; diff --git a/sys/boot/forth/menusets.4th.8 b/sys/boot/forth/menusets.4th.8 new file mode 100644 index 0000000..e05e4a7 --- /dev/null +++ b/sys/boot/forth/menusets.4th.8 @@ -0,0 +1,372 @@ +.\" Copyright (c) 2012 Devin Teske +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd November 5, 2012 +.Dt MENUSETS.4TH 8 +.Os +.Sh NAME +.Nm menusets.4th +.Nd FreeBSD dynamic submenu boot module +.Sh DESCRIPTION +The file that goes by the name of +.Nm +is a set of commands designed to add submenu functionality to the dynamic menu +system provided by +.Xr menu.4th 8 . +Submenus are managed through a system of carefully named environment variables. +The commands of +.Nm +by themselves are not enough for most uses. +Please refer to the examples below for the most common situations, and to +.Xr menu.4th 8 +for additional commands. +.Pp +Before using any of the commands provided in +.Nm , +it must be included +through the command: +.Pp +.Dl include menusets.4th +.Pp +This line is present in the default +.Pa /boot/menu-commands.4th +file, so it is not needed (and should not be re-issued) in a normal setup. +.Pp +The commands provided by it are: +.Pp +.Bl -tag -width menuset-loadinitial -compact -offset indent +.It Ic menuset-loadsetnum +Takes a single integer on the stack to identify the menuset environment +variables to be activated (see environment variables below). +.It Ic menuset-loadinitial +If $menuset_initial is set, passes the value to menuset-loadsetnum. +The value must be a number. +.It Ic menusets-unset +Unsets the environment variables associated with all menusets. +Increments starting at 1 and stops at the first unconfigured menuset. +A menuset is considered configured if the caption for item 1 is set. +.El +.Pp +The environment variables that effect its behavior are: +.Bl -tag -width bootfile -offset indent +.It Va menuset_initial +Number to pass to menuset-loadsetnum when menuset-loadinitial is called. +.It Va menuset_nameN +Used to give a name to a menuset. +.El +.Pp +When a menuset is NOT given a name (the default), +menuset N is comprised of the following environment variables: +.Pp +.Bl -tag -width menusetN_caption[x][y] -compact -offset indent +.It Va ansisetN_caption[x] +-> ansi_caption[x] +.It Va ansisetN_caption[x][y] +-> ansi_caption[x][y] +.It Va menusetN_acpi +-> menu_acpi +.It Va menusetN_caption[x] +-> menu_caption[x] +.It Va menusetN_caption[x][y] +-> menu_caption[x][y] +.It Va menusetN_command[x] +-> menu_command[x] +.It Va menusetN_init +-> +.Dq Li evaluated +.It Va menusetN_init[x] +-> menu_init[x] +.It Va menusetN_keycode[x] +-> menu_keycode[x] +.It Va menusetN_options +-> menu_options +.It Va menusetN_optionstext +-> menu_optionstext +.It Va menusetN_reboot +-> menu_reboot +.It Va toggledsetN_ansi[x] +-> toggled_ansi[x] +.It Va toggledsetN_text[x] +-> toggled_text[x] +.El +.Pp +When you choose to give a menuset a name (by setting $menuset_nameN), +menuset N is instead comprised of the following environment variables: +.Pp +.Bl -tag -width NAMEmenu_caption[x][y] -compact -offset indent +.It Va NAMEansi_caption[x] +-> ansi_caption[x] +.It Va NAMEansi_caption[x][y] +-> ansi_caption[x][y] +.It Va NAMEmenu_acpi +-> menu_acpi +.It Va NAMEmenu_caption[x] +-> menu_caption[x] +.It Va NAMEmenu_caption[x][y] +-> menu_caption[x][y] +.It Va NAMEmenu_command[x] +-> menu_command[x] +.It Va NAMEmenu_init +-> +.Dq Li evaluated +.It Va NAMEmenu_init[x] +-> menu_init[x] +.It Va NAMEmenu_keycode[x] +-> menu_keycode[x] +.It Va NAMEmenu_options +-> menu_options +.It Va NAMEmenu_optionstext +-> menu_optionstext +.It Va NAMEmenu_reboot +-> menu_reboot +.It Va NAMEtoggled_ansi[x] +-> toggled_ansi[x] +.It Va NAMEtoggled_text[x] +-> toggled_text[x] +.El +.Pp +where +.Dq Li NAME +is the value of $menuset_nameN. +In the case of $NAMEmenu_init ($menusetN_init when $menuset_nameN is unset), +the value is evaluated as an FICL statement. +This can be used to dynamically adjust the menuset variables right before the +menu is activated. +.Pp +In addition, +.Nm +provides the following FICL words: +.Pp +.Bl -tag -width menuset -compact -offset indent +.It Ic menuset-checksetnum ( N -- ) +Given a single integer on the stack, sets a global variable +.Va menuset_use_name +to a boolean based on whether $menuset_nameN is set (true) or not (false). +Also sets $affix temporary variable (prefix or infix depending on +menuset_use_name). +Automatically called by menuset-loadsetnum and menusets-unset. +.It Ic menuset-loadvar ( -- ) +Used indirectly to shorten syntax and mitigate dictionary size. +Requires the following temporary environment variables: +.Pp +.Bl -tag -width affix -compact -offset indent +.It Va type +should be set to one of: menu toggled ansi +.It Va var +should be set to one of: caption command keycode text ... +.It Va affix +either a prefix (menuset_use_name is true) or infix (menuset_use_name is false) +.El +.Pp +If the global +.Va menuset_use_name +is true, the variable ${type}_${var} is made to +equal the value of the variable ${affix}${type}_${var} +(note: in this case menuset-checksetnum has set $affix to $menuset_nameN). +Otherwise (when +.Va menuset_use_name +is false), the variable ${type}_${var} is made to +equal the value of the variable ${type}set${affix}_${var} +(note: in this case menuset-checksetnum has set $affix to N). +.Pp +Both the global variable +.Va menuset_use_name +and the environment variable $affix are automatically handled by +menuset-checksetnum above (which is automatically called by +menuset-loadsetnum). +.It Ic menuset-unloadvar ( -- ) +Used indirectly to shorten syntax and mitigate dictionary size. +Like menuset-loadvar except it unsets the menuset variable. +If global +.Va menuset_use_name +is true ($affix is $menuset_nameN), +variable ${affix}${type}_${var} is unset. +Otherwise, $affix is N and variable ${type}set${affix}_${var} is unset. +.It Ic menuset-loadmenuvar ( -- ) +Sets $type to +.Dq menu +and calls menuset-loadvar. +.It Ic menuset-unloadmenuvar ( -- ) +Sets $type to +.Dq menu +and calls menuset-unloadvar. +.It Ic menuset-loadxvar ( -- ) +Like menuset-loadvar except it takes an additional temporary variable $x. +If the global +.Va menuset_use_name +is true (making $affix equal $menuset_nameN), +sets variable ${type}_${var}[${x}] to variable ${affix}${type}_${var}[${x}]. +Otherwise ($affix being N), sets the same variable to instead +${type}set{affix}_${var}[${x}]. +.It Ic menuset-unloadxvar ( -- ) +Like menuset-loadxvar except it unsets the menuset variable. +If global +.Va menuset_use_name +is true, unsets ${affix}${type}_${var}[${x}]. +Otherwise, unsets ${type}set${affix}_${var}[${x}]. +.It Ic menuset-loadansixvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-loadxvar +.It Ic menuset-unloadansixvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-unloadxvar +.It Ic menuset-loadmenuxvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-loadxvar +.It Ic menuset-unloadmenuxvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-unloadxvar +.It Ic menuset-loadtoggledxvar ( -- ) +Sets $type to +.Dq toggled +and calls menuset-loadxvar +.It Ic menuset-unloadtoggledxvar ( -- ) +Sets $type to +.Dq toggled +and calls menuset-unloadxvar +.It Ic menuset-loadxyvar ( -- ) +Like menuset-loadxvar except it takes an additional temporary variable $y. +If the global +.Va menuset_use_name +is true ($affix is $menuset_nameN), +sets variable ${type}_${var}[${x}][${y}] to ${affix}${type}_${var}[${x}][${y}]. +Otherwise ($affix is N) sets the same variable to instead +${type}set${affix}_${var}[${x}][${y}]. +.It Ic menuset-unloadxyvar ( -- ) +Like menuset-loadxyvar except it unsets the menuset variable. +If the global +.Va menuset_use_name +is true, unsets ${affix}${type}_${var}[${x}][${y}]. +Otherwise, unsets ${type}set${affix}_${var}[${x}][${y}]. +.It Ic menuset-loadansixyvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-loadxyvar. +.It Ic menuset-unloadansixyvar ( -- ) +Sets $type to +.Dq ansi +and calls menuset-unloadxyvar. +.It Ic menuset-loadmenuxyvar ( -- ) +Sets $type to +.Dq menu +and calls menuset-loadxyvar. +.It Ic menuset-unloadmenuxyvar ( -- ) +Sets $type to +.Dq menu +and calls menuset-unloadxyvar. +.It Ic menuset-setnum-namevar ( N -- C-Addr/U ) +Takes a single integer on the stack and replaces it with a string (in c-addr/u +format) whose value is +.Dq menuset_nameN . +For example, if given 1 returns +.Dq menuset_name1 . +.It Ic menuset-cleanup ( N -- ) +Unsets all the various temporary variables, currently +.Va type , +.Va var , +.Va x , +.Va y , +and +.Va affix . +.El +.Pp +For all values of +.Dq Li x +above, use any number between 1 through 9. Sorry, double-digits are not +currently supported. +For all values of +.Dq Li N +above, use any number between 1 and 65535. +.Sh FILES +.Bl -tag -width /boot/menu-commands.4th -compact +.It Pa /boot/loader +The +.Xr loader 8 . +.It Pa /boot/menu.4th +Dynamic menu module. +.It Pa /boot/menu-commands.4th +Contains the goto_menu command. +.It Pa /boot/menusets.4th +.Nm +itself. +.It Pa /boot/loader.rc +.Xr loader 8 +bootstrapping script. +.El +.Sh EXAMPLES +A simple boot menu with a submenu: +.Pp +.Bd -literal -offset indent -compact +include /boot/menu.4th +include /boot/menu-commands.4th +menu-init +set menuset1_caption[1]="Boot" +set menuset1_command[1]="boot" +set menuset1_caption[2]="Submenu..." +set menuset1_command[2]="2 goto_menu" +set menuset2_caption[1]="Back" +set menuset2_command[1]="1 goto_menu" +set menuset_initial=2 +menuset-loadinitial +menu-display +.Ed +.Pp +The same boot menu with named menusets: +.Pp +.Bd -literal -offset indent -compact +include /boot/menu.4th +include /boot/menu-commands.4th +menu-init +set menuset_name1=main +set mainmenu_caption[1]="Boot" +set mainmenu_command[1]="boot" +set mainmenu_caption[2]="Submenu..." +set mainmenu_command[2]="2 goto_menu" +set menuset_name2=sub +set submenu_caption[1]="Back" +set submenu_command[1]="1 goto_menu" +.Ed +.Sh SEE ALSO +.Xr loader.conf 5 , +.Xr loader 8 , +.Xr loader.4th 8 , +.Xr menu.4th 8 , +.Xr beastie.4th 8 +.Sh HISTORY +The +.Nm +set of commands first appeared in +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +set of commands was written by +.An -nosplit +.An Devin Teske Aq dteske@FreeBSD.org . |