1*ca987d46SWarner Losh\ Copyright (c) 2012 Devin Teske <dteske@FreeBSD.org> 2*ca987d46SWarner Losh\ All rights reserved. 3*ca987d46SWarner Losh\ 4*ca987d46SWarner Losh\ Redistribution and use in source and binary forms, with or without 5*ca987d46SWarner Losh\ modification, are permitted provided that the following conditions 6*ca987d46SWarner Losh\ are met: 7*ca987d46SWarner Losh\ 1. Redistributions of source code must retain the above copyright 8*ca987d46SWarner Losh\ notice, this list of conditions and the following disclaimer. 9*ca987d46SWarner Losh\ 2. Redistributions in binary form must reproduce the above copyright 10*ca987d46SWarner Losh\ notice, this list of conditions and the following disclaimer in the 11*ca987d46SWarner Losh\ documentation and/or other materials provided with the distribution. 12*ca987d46SWarner Losh\ 13*ca987d46SWarner Losh\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*ca987d46SWarner Losh\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*ca987d46SWarner Losh\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*ca987d46SWarner Losh\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*ca987d46SWarner Losh\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*ca987d46SWarner Losh\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*ca987d46SWarner Losh\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*ca987d46SWarner Losh\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*ca987d46SWarner Losh\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*ca987d46SWarner Losh\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*ca987d46SWarner Losh\ SUCH DAMAGE. 24*ca987d46SWarner Losh\ 25*ca987d46SWarner Losh 26*ca987d46SWarner Loshmarker task-menusets.4th 27*ca987d46SWarner Losh 28*ca987d46SWarner Loshvocabulary menusets-infrastructure 29*ca987d46SWarner Loshonly forth also menusets-infrastructure definitions 30*ca987d46SWarner Losh 31*ca987d46SWarner Loshvariable menuset_use_name 32*ca987d46SWarner Losh 33*ca987d46SWarner Loshcreate menuset_affixbuf 255 allot 34*ca987d46SWarner Loshcreate menuset_x 1 allot 35*ca987d46SWarner Loshcreate menuset_y 1 allot 36*ca987d46SWarner Losh 37*ca987d46SWarner Losh: menuset-loadvar ( -- ) 38*ca987d46SWarner Losh 39*ca987d46SWarner Losh \ menuset_use_name is true or false 40*ca987d46SWarner Losh \ $type should be set to one of: 41*ca987d46SWarner Losh \ menu toggled ansi 42*ca987d46SWarner Losh \ $var should be set to one of: 43*ca987d46SWarner Losh \ caption command keycode text ... 44*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 45*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 46*ca987d46SWarner Losh 47*ca987d46SWarner Losh s" set cmdbuf='set ${type}_${var}=\$'" evaluate 48*ca987d46SWarner Losh s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length 49*ca987d46SWarner Losh menuset_use_name @ true = if 50*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${affix}${type}_${var}" 51*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 52*ca987d46SWarner Losh else 53*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}" 54*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 55*ca987d46SWarner Losh then 56*ca987d46SWarner Losh evaluate ( u1 c-addr2 u2 -- u1 ) 57*ca987d46SWarner Losh s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) 58*ca987d46SWarner Losh rot 2 pick 2 pick over + -rot + tuck - 59*ca987d46SWarner Losh ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) 60*ca987d46SWarner Losh \ Generate a string representing rvalue inheritance var 61*ca987d46SWarner Losh getenv dup -1 = if 62*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) 63*ca987d46SWarner Losh \ NOT set -- clean up the stack 64*ca987d46SWarner Losh drop ( c-addr2 u2 -1 -- c-addr2 u2 ) 65*ca987d46SWarner Losh 2drop ( c-addr2 u2 -- ) 66*ca987d46SWarner Losh else 67*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) 68*ca987d46SWarner Losh \ SET -- execute cmdbuf (c-addr2/u2) to inherit value 69*ca987d46SWarner Losh 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) 70*ca987d46SWarner Losh evaluate ( c-addr2 u2 -- ) 71*ca987d46SWarner Losh then 72*ca987d46SWarner Losh 73*ca987d46SWarner Losh s" cmdbuf" unsetenv 74*ca987d46SWarner Losh; 75*ca987d46SWarner Losh 76*ca987d46SWarner Losh: menuset-unloadvar ( -- ) 77*ca987d46SWarner Losh 78*ca987d46SWarner Losh \ menuset_use_name is true or false 79*ca987d46SWarner Losh \ $type should be set to one of: 80*ca987d46SWarner Losh \ menu toggled ansi 81*ca987d46SWarner Losh \ $var should be set to one of: 82*ca987d46SWarner Losh \ caption command keycode text ... 83*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 84*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 85*ca987d46SWarner Losh 86*ca987d46SWarner Losh menuset_use_name @ true = if 87*ca987d46SWarner Losh s" set buf=${affix}${type}_${var}" 88*ca987d46SWarner Losh else 89*ca987d46SWarner Losh s" set buf=${type}set${affix}_${var}" 90*ca987d46SWarner Losh then 91*ca987d46SWarner Losh evaluate 92*ca987d46SWarner Losh s" buf" getenv unsetenv 93*ca987d46SWarner Losh s" buf" unsetenv 94*ca987d46SWarner Losh; 95*ca987d46SWarner Losh 96*ca987d46SWarner Losh: menuset-loadmenuvar ( -- ) 97*ca987d46SWarner Losh s" set type=menu" evaluate 98*ca987d46SWarner Losh menuset-loadvar 99*ca987d46SWarner Losh; 100*ca987d46SWarner Losh 101*ca987d46SWarner Losh: menuset-unloadmenuvar ( -- ) 102*ca987d46SWarner Losh s" set type=menu" evaluate 103*ca987d46SWarner Losh menuset-unloadvar 104*ca987d46SWarner Losh; 105*ca987d46SWarner Losh 106*ca987d46SWarner Losh: menuset-loadxvar ( -- ) 107*ca987d46SWarner Losh 108*ca987d46SWarner Losh \ menuset_use_name is true or false 109*ca987d46SWarner Losh \ $type should be set to one of: 110*ca987d46SWarner Losh \ menu toggled ansi 111*ca987d46SWarner Losh \ $var should be set to one of: 112*ca987d46SWarner Losh \ caption command keycode text ... 113*ca987d46SWarner Losh \ $x is "1" through "8" 114*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 115*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 116*ca987d46SWarner Losh 117*ca987d46SWarner Losh s" set cmdbuf='set ${type}_${var}[${x}]=\$'" evaluate 118*ca987d46SWarner Losh s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length 119*ca987d46SWarner Losh menuset_use_name @ true = if 120*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${affix}${type}_${var}[${x}]" 121*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 122*ca987d46SWarner Losh else 123*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}[${x}]" 124*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 125*ca987d46SWarner Losh then 126*ca987d46SWarner Losh evaluate ( u1 c-addr2 u2 -- u1 ) 127*ca987d46SWarner Losh s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) 128*ca987d46SWarner Losh rot 2 pick 2 pick over + -rot + tuck - 129*ca987d46SWarner Losh ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) 130*ca987d46SWarner Losh \ Generate a string representing rvalue inheritance var 131*ca987d46SWarner Losh getenv dup -1 = if 132*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) 133*ca987d46SWarner Losh \ NOT set -- clean up the stack 134*ca987d46SWarner Losh drop ( c-addr2 u2 -1 -- c-addr2 u2 ) 135*ca987d46SWarner Losh 2drop ( c-addr2 u2 -- ) 136*ca987d46SWarner Losh else 137*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) 138*ca987d46SWarner Losh \ SET -- execute cmdbuf (c-addr2/u2) to inherit value 139*ca987d46SWarner Losh 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) 140*ca987d46SWarner Losh evaluate ( c-addr2 u2 -- ) 141*ca987d46SWarner Losh then 142*ca987d46SWarner Losh 143*ca987d46SWarner Losh s" cmdbuf" unsetenv 144*ca987d46SWarner Losh; 145*ca987d46SWarner Losh 146*ca987d46SWarner Losh: menuset-unloadxvar ( -- ) 147*ca987d46SWarner Losh 148*ca987d46SWarner Losh \ menuset_use_name is true or false 149*ca987d46SWarner Losh \ $type should be set to one of: 150*ca987d46SWarner Losh \ menu toggled ansi 151*ca987d46SWarner Losh \ $var should be set to one of: 152*ca987d46SWarner Losh \ caption command keycode text ... 153*ca987d46SWarner Losh \ $x is "1" through "8" 154*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 155*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 156*ca987d46SWarner Losh 157*ca987d46SWarner Losh menuset_use_name @ true = if 158*ca987d46SWarner Losh s" set buf=${affix}${type}_${var}[${x}]" 159*ca987d46SWarner Losh else 160*ca987d46SWarner Losh s" set buf=${type}set${affix}_${var}[${x}]" 161*ca987d46SWarner Losh then 162*ca987d46SWarner Losh evaluate 163*ca987d46SWarner Losh s" buf" getenv unsetenv 164*ca987d46SWarner Losh s" buf" unsetenv 165*ca987d46SWarner Losh; 166*ca987d46SWarner Losh 167*ca987d46SWarner Losh: menuset-loadansixvar ( -- ) 168*ca987d46SWarner Losh s" set type=ansi" evaluate 169*ca987d46SWarner Losh menuset-loadxvar 170*ca987d46SWarner Losh; 171*ca987d46SWarner Losh 172*ca987d46SWarner Losh: menuset-unloadansixvar ( -- ) 173*ca987d46SWarner Losh s" set type=ansi" evaluate 174*ca987d46SWarner Losh menuset-unloadxvar 175*ca987d46SWarner Losh; 176*ca987d46SWarner Losh 177*ca987d46SWarner Losh: menuset-loadmenuxvar ( -- ) 178*ca987d46SWarner Losh s" set type=menu" evaluate 179*ca987d46SWarner Losh menuset-loadxvar 180*ca987d46SWarner Losh; 181*ca987d46SWarner Losh 182*ca987d46SWarner Losh: menuset-unloadmenuxvar ( -- ) 183*ca987d46SWarner Losh s" set type=menu" evaluate 184*ca987d46SWarner Losh menuset-unloadxvar 185*ca987d46SWarner Losh; 186*ca987d46SWarner Losh 187*ca987d46SWarner Losh: menuset-loadtoggledxvar ( -- ) 188*ca987d46SWarner Losh s" set type=toggled" evaluate 189*ca987d46SWarner Losh menuset-loadxvar 190*ca987d46SWarner Losh; 191*ca987d46SWarner Losh 192*ca987d46SWarner Losh: menuset-unloadtoggledxvar ( -- ) 193*ca987d46SWarner Losh s" set type=toggled" evaluate 194*ca987d46SWarner Losh menuset-unloadxvar 195*ca987d46SWarner Losh; 196*ca987d46SWarner Losh 197*ca987d46SWarner Losh: menuset-loadxyvar ( -- ) 198*ca987d46SWarner Losh 199*ca987d46SWarner Losh \ menuset_use_name is true or false 200*ca987d46SWarner Losh \ $type should be set to one of: 201*ca987d46SWarner Losh \ menu toggled ansi 202*ca987d46SWarner Losh \ $var should be set to one of: 203*ca987d46SWarner Losh \ caption command keycode text ... 204*ca987d46SWarner Losh \ $x is "1" through "8" 205*ca987d46SWarner Losh \ $y is "0" through "9" 206*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 207*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 208*ca987d46SWarner Losh 209*ca987d46SWarner Losh s" set cmdbuf='set ${type}_${var}[${x}][${y}]=\$'" evaluate 210*ca987d46SWarner Losh s" cmdbuf" getenv swap drop ( -- u1 ) \ get string length 211*ca987d46SWarner Losh menuset_use_name @ true = if 212*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${affix}${type}_${var}[${x}][${y}]" 213*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 214*ca987d46SWarner Losh else 215*ca987d46SWarner Losh s" set cmdbuf=${cmdbuf}${type}set${affix}_${var}[${x}][${y}]" 216*ca987d46SWarner Losh ( u1 -- u1 c-addr2 u2 ) 217*ca987d46SWarner Losh then 218*ca987d46SWarner Losh evaluate ( u1 c-addr2 u2 -- u1 ) 219*ca987d46SWarner Losh s" cmdbuf" getenv ( u1 -- u1 c-addr2 u2 ) 220*ca987d46SWarner Losh rot 2 pick 2 pick over + -rot + tuck - 221*ca987d46SWarner Losh ( u1 c-addr2 u2 -- c-addr2 u2 c-addr1 u1 ) 222*ca987d46SWarner Losh \ Generate a string representing rvalue inheritance var 223*ca987d46SWarner Losh getenv dup -1 = if 224*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 -1 ) 225*ca987d46SWarner Losh \ NOT set -- clean up the stack 226*ca987d46SWarner Losh drop ( c-addr2 u2 -1 -- c-addr2 u2 ) 227*ca987d46SWarner Losh 2drop ( c-addr2 u2 -- ) 228*ca987d46SWarner Losh else 229*ca987d46SWarner Losh ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 c-addr1 u1 ) 230*ca987d46SWarner Losh \ SET -- execute cmdbuf (c-addr2/u2) to inherit value 231*ca987d46SWarner Losh 2drop ( c-addr2 u2 c-addr1 u1 -- c-addr2 u2 ) 232*ca987d46SWarner Losh evaluate ( c-addr2 u2 -- ) 233*ca987d46SWarner Losh then 234*ca987d46SWarner Losh 235*ca987d46SWarner Losh s" cmdbuf" unsetenv 236*ca987d46SWarner Losh; 237*ca987d46SWarner Losh 238*ca987d46SWarner Losh: menuset-unloadxyvar ( -- ) 239*ca987d46SWarner Losh 240*ca987d46SWarner Losh \ menuset_use_name is true or false 241*ca987d46SWarner Losh \ $type should be set to one of: 242*ca987d46SWarner Losh \ menu toggled ansi 243*ca987d46SWarner Losh \ $var should be set to one of: 244*ca987d46SWarner Losh \ caption command keycode text ... 245*ca987d46SWarner Losh \ $x is "1" through "8" 246*ca987d46SWarner Losh \ $y is "0" through "9" 247*ca987d46SWarner Losh \ $affix is either prefix (menuset_use_name is true) 248*ca987d46SWarner Losh \ or infix (menuset_use_name is false) 249*ca987d46SWarner Losh 250*ca987d46SWarner Losh menuset_use_name @ true = if 251*ca987d46SWarner Losh s" set buf=${affix}${type}_${var}[${x}][${y}]" 252*ca987d46SWarner Losh else 253*ca987d46SWarner Losh s" set buf=${type}set${affix}_${var}[${x}][${y}]" 254*ca987d46SWarner Losh then 255*ca987d46SWarner Losh evaluate 256*ca987d46SWarner Losh s" buf" getenv unsetenv 257*ca987d46SWarner Losh s" buf" unsetenv 258*ca987d46SWarner Losh; 259*ca987d46SWarner Losh 260*ca987d46SWarner Losh: menuset-loadansixyvar ( -- ) 261*ca987d46SWarner Losh s" set type=ansi" evaluate 262*ca987d46SWarner Losh menuset-loadxyvar 263*ca987d46SWarner Losh; 264*ca987d46SWarner Losh 265*ca987d46SWarner Losh: menuset-unloadansixyvar ( -- ) 266*ca987d46SWarner Losh s" set type=ansi" evaluate 267*ca987d46SWarner Losh menuset-unloadxyvar 268*ca987d46SWarner Losh; 269*ca987d46SWarner Losh 270*ca987d46SWarner Losh: menuset-loadmenuxyvar ( -- ) 271*ca987d46SWarner Losh s" set type=menu" evaluate 272*ca987d46SWarner Losh menuset-loadxyvar 273*ca987d46SWarner Losh; 274*ca987d46SWarner Losh 275*ca987d46SWarner Losh: menuset-unloadmenuxyvar ( -- ) 276*ca987d46SWarner Losh s" set type=menu" evaluate 277*ca987d46SWarner Losh menuset-unloadxyvar 278*ca987d46SWarner Losh; 279*ca987d46SWarner Losh 280*ca987d46SWarner Losh: menuset-setnum-namevar ( N -- C-Addr/U ) 281*ca987d46SWarner Losh 282*ca987d46SWarner Losh s" menuset_nameNNNNN" ( n -- n c-addr1 u1 ) \ variable basename 283*ca987d46SWarner Losh drop 12 ( n c-addr1 u1 -- n c-addr1 12 ) \ remove "NNNNN" 284*ca987d46SWarner Losh rot ( n c-addr1 12 -- c-addr1 12 n ) \ move number on top 285*ca987d46SWarner Losh 286*ca987d46SWarner Losh \ convert to string 287*ca987d46SWarner Losh s>d <# #s #> ( c-addr1 12 n -- c-addr1 12 c-addr2 u2 ) 288*ca987d46SWarner Losh 289*ca987d46SWarner Losh \ Combine strings 290*ca987d46SWarner Losh begin ( using u2 in c-addr2/u2 pair as countdown to zero ) 291*ca987d46SWarner Losh over ( c-addr1 u1 c-addr2 u2 -- continued below ) 292*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c-addr2 ) \ copy src-addr 293*ca987d46SWarner Losh c@ ( c-addr1 u1 c-addr2 u2 c-addr2 -- continued below ) 294*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c ) \ get next src-addr byte 295*ca987d46SWarner Losh 4 pick 4 pick 296*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c -- continued below ) 297*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 ) 298*ca987d46SWarner Losh \ get destination c-addr1/u1 pair 299*ca987d46SWarner Losh + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 -- cont. below ) 300*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c c-addr3 ) 301*ca987d46SWarner Losh \ combine dest-c-addr to get dest-addr for byte 302*ca987d46SWarner Losh c! ( c-addr1 u1 c-addr2 u2 c c-addr3 -- continued below ) 303*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 ) 304*ca987d46SWarner Losh \ store the current src-addr byte into dest-addr 305*ca987d46SWarner Losh 306*ca987d46SWarner Losh 2swap 1+ 2swap \ increment u1 in destination c-addr1/u1 pair 307*ca987d46SWarner Losh swap 1+ swap \ increment c-addr2 in source c-addr2/u2 pair 308*ca987d46SWarner Losh 1- \ decrement u2 in the source c-addr2/u2 pair 309*ca987d46SWarner Losh 310*ca987d46SWarner Losh dup 0= \ time to break? 311*ca987d46SWarner Losh until 312*ca987d46SWarner Losh 313*ca987d46SWarner Losh 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 ) 314*ca987d46SWarner Losh \ drop temporary number-format conversion c-addr2/u2 315*ca987d46SWarner Losh; 316*ca987d46SWarner Losh 317*ca987d46SWarner Losh: menuset-checksetnum ( N -- ) 318*ca987d46SWarner Losh 319*ca987d46SWarner Losh \ 320*ca987d46SWarner Losh \ adjust input to be both positive and no-higher than 65535 321*ca987d46SWarner Losh \ 322*ca987d46SWarner Losh abs dup 65535 > if drop 65535 then ( n -- n ) 323*ca987d46SWarner Losh 324*ca987d46SWarner Losh \ 325*ca987d46SWarner Losh \ The next few blocks will determine if we should use the default 326*ca987d46SWarner Losh \ methodology (referencing the original numeric stack-input), or if- 327*ca987d46SWarner Losh \ instead $menuset_name{N} has been defined wherein we would then 328*ca987d46SWarner Losh \ use the value thereof as the prefix to every menu variable. 329*ca987d46SWarner Losh \ 330*ca987d46SWarner Losh 331*ca987d46SWarner Losh false menuset_use_name ! \ assume name is not set 332*ca987d46SWarner Losh 333*ca987d46SWarner Losh menuset-setnum-namevar 334*ca987d46SWarner Losh \ 335*ca987d46SWarner Losh \ We now have a string that is the assembled variable name to check 336*ca987d46SWarner Losh \ for... $menuset_name{N}. Let's check for it. 337*ca987d46SWarner Losh \ 338*ca987d46SWarner Losh 2dup ( c-addr1 u1 -- c-addr1 u1 c-addr1 u1 ) \ save a copy 339*ca987d46SWarner Losh getenv dup -1 <> if ( c-addr1 u1 c-addr1 u1 -- c-addr1 u1 c-addr2 u2 ) 340*ca987d46SWarner Losh \ The variable is set. Let's clean up the stack leaving only 341*ca987d46SWarner Losh \ its value for later use. 342*ca987d46SWarner Losh 343*ca987d46SWarner Losh true menuset_use_name ! 344*ca987d46SWarner Losh 2swap 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr2 u2 ) 345*ca987d46SWarner Losh \ drop assembled variable name, leave the value 346*ca987d46SWarner Losh else ( c-addr1 u1 c-addr1 u1 -- c-addr1 u1 -1 ) \ no such variable 347*ca987d46SWarner Losh \ The variable is not set. Let's clean up the stack leaving the 348*ca987d46SWarner Losh \ string [portion] representing the original numeric input. 349*ca987d46SWarner Losh 350*ca987d46SWarner Losh drop ( c-addr1 u1 -1 -- c-addr1 u1 ) \ drop -1 result 351*ca987d46SWarner Losh 12 - swap 12 + swap ( c-addr1 u1 -- c-addr2 u2 ) 352*ca987d46SWarner Losh \ truncate to original numeric stack-input 353*ca987d46SWarner Losh then 354*ca987d46SWarner Losh 355*ca987d46SWarner Losh \ 356*ca987d46SWarner Losh \ Now, depending on whether $menuset_name{N} has been set, we have 357*ca987d46SWarner Losh \ either the value thereof to be used as a prefix to all menu_* 358*ca987d46SWarner Losh \ variables or we have a string representing the numeric stack-input 359*ca987d46SWarner Losh \ to be used as a "set{N}" infix to the same menu_* variables. 360*ca987d46SWarner Losh \ 361*ca987d46SWarner Losh \ For example, if the stack-input is 1 and menuset_name1 is NOT set 362*ca987d46SWarner Losh \ the following variables will be referenced: 363*ca987d46SWarner Losh \ ansiset1_caption[x] -> ansi_caption[x] 364*ca987d46SWarner Losh \ ansiset1_caption[x][y] -> ansi_caption[x][y] 365*ca987d46SWarner Losh \ menuset1_acpi -> menu_acpi 366*ca987d46SWarner Losh \ menuset1_caption[x] -> menu_caption[x] 367*ca987d46SWarner Losh \ menuset1_caption[x][y] -> menu_caption[x][y] 368*ca987d46SWarner Losh \ menuset1_command[x] -> menu_command[x] 369*ca987d46SWarner Losh \ menuset1_init -> ``evaluated'' 370*ca987d46SWarner Losh \ menuset1_init[x] -> menu_init[x] 371*ca987d46SWarner Losh \ menuset1_kernel -> menu_kernel 372*ca987d46SWarner Losh \ menuset1_keycode[x] -> menu_keycode[x] 373*ca987d46SWarner Losh \ menuset1_options -> menu_options 374*ca987d46SWarner Losh \ menuset1_optionstext -> menu_optionstext 375*ca987d46SWarner Losh \ menuset1_reboot -> menu_reboot 376*ca987d46SWarner Losh \ toggledset1_ansi[x] -> toggled_ansi[x] 377*ca987d46SWarner Losh \ toggledset1_text[x] -> toggled_text[x] 378*ca987d46SWarner Losh \ otherwise, the following variables are referenced (where {name} 379*ca987d46SWarner Losh \ represents the value of $menuset_name1 (given 1 as stack-input): 380*ca987d46SWarner Losh \ {name}ansi_caption[x] -> ansi_caption[x] 381*ca987d46SWarner Losh \ {name}ansi_caption[x][y] -> ansi_caption[x][y] 382*ca987d46SWarner Losh \ {name}menu_acpi -> menu_acpi 383*ca987d46SWarner Losh \ {name}menu_caption[x] -> menu_caption[x] 384*ca987d46SWarner Losh \ {name}menu_caption[x][y] -> menu_caption[x][y] 385*ca987d46SWarner Losh \ {name}menu_command[x] -> menu_command[x] 386*ca987d46SWarner Losh \ {name}menu_init -> ``evaluated'' 387*ca987d46SWarner Losh \ {name}menu_init[x] -> menu_init[x] 388*ca987d46SWarner Losh \ {name}menu_kernel -> menu_kernel 389*ca987d46SWarner Losh \ {name}menu_keycode[x] -> menu_keycode[x] 390*ca987d46SWarner Losh \ {name}menu_options -> menu_options 391*ca987d46SWarner Losh \ {name}menu_optionstext -> menu_optionstext 392*ca987d46SWarner Losh \ {name}menu_reboot -> menu_reboot 393*ca987d46SWarner Losh \ {name}toggled_ansi[x] -> toggled_ansi[x] 394*ca987d46SWarner Losh \ {name}toggled_text[x] -> toggled_text[x] 395*ca987d46SWarner Losh \ 396*ca987d46SWarner Losh \ Note that menuset{N}_init and {name}menu_init are the initializers 397*ca987d46SWarner Losh \ for the entire menu (for wholly dynamic menus) opposed to the per- 398*ca987d46SWarner Losh \ menuitem initializers (with [x] afterward). The whole-menu init 399*ca987d46SWarner Losh \ routine is evaluated and not passed down to $menu_init (which 400*ca987d46SWarner Losh \ would result in double evaluation). By doing this, the initializer 401*ca987d46SWarner Losh \ can initialize the menuset before we transfer it to active-duty. 402*ca987d46SWarner Losh \ 403*ca987d46SWarner Losh 404*ca987d46SWarner Losh \ 405*ca987d46SWarner Losh \ Copy our affixation (prefix or infix depending on menuset_use_name) 406*ca987d46SWarner Losh \ to our buffer so that we can safely use the s-quote (s") buf again. 407*ca987d46SWarner Losh \ 408*ca987d46SWarner Losh menuset_affixbuf 0 2swap ( c-addr2 u2 -- c-addr1 0 c-addr2 u2 ) 409*ca987d46SWarner Losh begin ( using u2 in c-addr2/u2 pair as countdown to zero ) 410*ca987d46SWarner Losh over ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 c-addr2 u2 c-addr2 ) 411*ca987d46SWarner Losh c@ ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 c-addr2 u2 c ) 412*ca987d46SWarner Losh 4 pick 4 pick 413*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c -- continued below ) 414*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 ) 415*ca987d46SWarner Losh + ( c-addr1 u1 c-addr2 u2 c c-addr1 u1 -- continued below ) 416*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 c c-addr3 ) 417*ca987d46SWarner Losh c! ( c-addr1 u1 c-addr2 u2 c c-addr3 -- continued below ) 418*ca987d46SWarner Losh ( c-addr1 u1 c-addr2 u2 ) 419*ca987d46SWarner Losh 2swap 1+ 2swap \ increment affixbuf byte position/count 420*ca987d46SWarner Losh swap 1+ swap \ increment strbuf pointer (source c-addr2) 421*ca987d46SWarner Losh 1- \ decrement strbuf byte count (source u2) 422*ca987d46SWarner Losh dup 0= \ time to break? 423*ca987d46SWarner Losh until 424*ca987d46SWarner Losh 2drop ( c-addr1 u1 c-addr2 u2 -- c-addr1 u1 ) \ drop strbuf c-addr2/u2 425*ca987d46SWarner Losh 426*ca987d46SWarner Losh \ 427*ca987d46SWarner Losh \ Create a variable for referencing our affix data (prefix or infix 428*ca987d46SWarner Losh \ depending on menuset_use_name as described above). This variable will 429*ca987d46SWarner Losh \ be temporary and only used to simplify cmdbuf assembly. 430*ca987d46SWarner Losh \ 431*ca987d46SWarner Losh s" affix" setenv ( c-addr1 u1 -- ) 432*ca987d46SWarner Losh; 433*ca987d46SWarner Losh 434*ca987d46SWarner Losh: menuset-cleanup ( -- ) 435*ca987d46SWarner Losh s" type" unsetenv 436*ca987d46SWarner Losh s" var" unsetenv 437*ca987d46SWarner Losh s" x" unsetenv 438*ca987d46SWarner Losh s" y" unsetenv 439*ca987d46SWarner Losh s" affix" unsetenv 440*ca987d46SWarner Losh; 441*ca987d46SWarner Losh 442*ca987d46SWarner Loshonly forth definitions also menusets-infrastructure 443*ca987d46SWarner Losh 444*ca987d46SWarner Losh: menuset-loadsetnum ( N -- ) 445*ca987d46SWarner Losh 446*ca987d46SWarner Losh menuset-checksetnum ( n -- ) 447*ca987d46SWarner Losh 448*ca987d46SWarner Losh \ 449*ca987d46SWarner Losh \ From here out, we use temporary environment variables to make 450*ca987d46SWarner Losh \ dealing with variable-length strings easier. 451*ca987d46SWarner Losh \ 452*ca987d46SWarner Losh \ menuset_use_name is true or false 453*ca987d46SWarner Losh \ $affix should be used appropriately w/respect to menuset_use_name 454*ca987d46SWarner Losh \ 455*ca987d46SWarner Losh 456*ca987d46SWarner Losh \ ... menu_init ... 457*ca987d46SWarner Losh s" set var=init" evaluate 458*ca987d46SWarner Losh menuset-loadmenuvar 459*ca987d46SWarner Losh 460*ca987d46SWarner Losh \ If menu_init was set by the above, evaluate it here-and-now 461*ca987d46SWarner Losh \ so that the remaining variables are influenced by its actions 462*ca987d46SWarner Losh s" menu_init" 2dup getenv dup -1 <> if 463*ca987d46SWarner Losh 2swap unsetenv \ don't want later menu-create to re-call this 464*ca987d46SWarner Losh evaluate 465*ca987d46SWarner Losh else 466*ca987d46SWarner Losh drop 2drop ( n c-addr u -1 -- n ) 467*ca987d46SWarner Losh then 468*ca987d46SWarner Losh 469*ca987d46SWarner Losh [char] 1 ( -- x ) \ Loop range ASCII '1' (49) to '8' (56) 470*ca987d46SWarner Losh begin 471*ca987d46SWarner Losh dup menuset_x tuck c! 1 s" x" setenv \ set loop iterator and $x 472*ca987d46SWarner Losh 473*ca987d46SWarner Losh s" set var=caption" evaluate 474*ca987d46SWarner Losh 475*ca987d46SWarner Losh \ ... menu_caption[x] ... 476*ca987d46SWarner Losh menuset-loadmenuxvar 477*ca987d46SWarner Losh 478*ca987d46SWarner Losh \ ... ansi_caption[x] ... 479*ca987d46SWarner Losh menuset-loadansixvar 480*ca987d46SWarner Losh 481*ca987d46SWarner Losh [char] 0 ( x -- x y ) \ Inner Loop ASCII '1' (48) to '9' (57) 482*ca987d46SWarner Losh begin 483*ca987d46SWarner Losh dup menuset_y tuck c! 1 s" y" setenv 484*ca987d46SWarner Losh \ set inner loop iterator and $y 485*ca987d46SWarner Losh 486*ca987d46SWarner Losh \ ... menu_caption[x][y] ... 487*ca987d46SWarner Losh menuset-loadmenuxyvar 488*ca987d46SWarner Losh 489*ca987d46SWarner Losh \ ... ansi_caption[x][y] ... 490*ca987d46SWarner Losh menuset-loadansixyvar 491*ca987d46SWarner Losh 492*ca987d46SWarner Losh 1+ dup 57 > ( x y -- y' 0|-1 ) \ increment and test 493*ca987d46SWarner Losh until 494*ca987d46SWarner Losh drop ( x y -- x ) 495*ca987d46SWarner Losh 496*ca987d46SWarner Losh \ ... menu_command[x] ... 497*ca987d46SWarner Losh s" set var=command" evaluate 498*ca987d46SWarner Losh menuset-loadmenuxvar 499*ca987d46SWarner Losh 500*ca987d46SWarner Losh \ ... menu_init[x] ... 501*ca987d46SWarner Losh s" set var=init" evaluate 502*ca987d46SWarner Losh menuset-loadmenuxvar 503*ca987d46SWarner Losh 504*ca987d46SWarner Losh \ ... menu_keycode[x] ... 505*ca987d46SWarner Losh s" set var=keycode" evaluate 506*ca987d46SWarner Losh menuset-loadmenuxvar 507*ca987d46SWarner Losh 508*ca987d46SWarner Losh \ ... toggled_text[x] ... 509*ca987d46SWarner Losh s" set var=text" evaluate 510*ca987d46SWarner Losh menuset-loadtoggledxvar 511*ca987d46SWarner Losh 512*ca987d46SWarner Losh \ ... toggled_ansi[x] ... 513*ca987d46SWarner Losh s" set var=ansi" evaluate 514*ca987d46SWarner Losh menuset-loadtoggledxvar 515*ca987d46SWarner Losh 516*ca987d46SWarner Losh 1+ dup 56 > ( x -- x' 0|-1 ) \ increment iterator 517*ca987d46SWarner Losh \ continue if less than 57 518*ca987d46SWarner Losh until 519*ca987d46SWarner Losh drop ( x -- ) \ loop iterator 520*ca987d46SWarner Losh 521*ca987d46SWarner Losh \ ... menu_reboot ... 522*ca987d46SWarner Losh s" set var=reboot" evaluate 523*ca987d46SWarner Losh menuset-loadmenuvar 524*ca987d46SWarner Losh 525*ca987d46SWarner Losh \ ... menu_acpi ... 526*ca987d46SWarner Losh s" set var=acpi" evaluate 527*ca987d46SWarner Losh menuset-loadmenuvar 528*ca987d46SWarner Losh 529*ca987d46SWarner Losh \ ... menu_kernel ... 530*ca987d46SWarner Losh s" set var=kernel" evaluate 531*ca987d46SWarner Losh menuset-loadmenuvar 532*ca987d46SWarner Losh 533*ca987d46SWarner Losh \ ... menu_options ... 534*ca987d46SWarner Losh s" set var=options" evaluate 535*ca987d46SWarner Losh menuset-loadmenuvar 536*ca987d46SWarner Losh 537*ca987d46SWarner Losh \ ... menu_optionstext ... 538*ca987d46SWarner Losh s" set var=optionstext" evaluate 539*ca987d46SWarner Losh menuset-loadmenuvar 540*ca987d46SWarner Losh 541*ca987d46SWarner Losh menuset-cleanup 542*ca987d46SWarner Losh; 543*ca987d46SWarner Losh 544*ca987d46SWarner Losh: menusets-unset ( -- ) 545*ca987d46SWarner Losh 546*ca987d46SWarner Losh s" menuset_initial" unsetenv 547*ca987d46SWarner Losh 548*ca987d46SWarner Losh 1 begin 549*ca987d46SWarner Losh dup menuset-checksetnum ( n n -- n ) 550*ca987d46SWarner Losh 551*ca987d46SWarner Losh dup menuset-setnum-namevar ( n n -- n ) 552*ca987d46SWarner Losh unsetenv 553*ca987d46SWarner Losh 554*ca987d46SWarner Losh \ If the current menuset does not populate the first menuitem, 555*ca987d46SWarner Losh \ we stop completely. 556*ca987d46SWarner Losh 557*ca987d46SWarner Losh menuset_use_name @ true = if 558*ca987d46SWarner Losh s" set buf=${affix}menu_caption[1]" 559*ca987d46SWarner Losh else 560*ca987d46SWarner Losh s" set buf=menuset${affix}_caption[1]" 561*ca987d46SWarner Losh then 562*ca987d46SWarner Losh evaluate s" buf" getenv getenv -1 = if 563*ca987d46SWarner Losh drop ( n -- ) 564*ca987d46SWarner Losh s" buf" unsetenv 565*ca987d46SWarner Losh menuset-cleanup 566*ca987d46SWarner Losh exit 567*ca987d46SWarner Losh else 568*ca987d46SWarner Losh drop ( n c-addr2 -- n ) \ unused 569*ca987d46SWarner Losh then 570*ca987d46SWarner Losh 571*ca987d46SWarner Losh [char] 1 ( n -- n x ) \ Loop range ASCII '1' (49) to '8' (56) 572*ca987d46SWarner Losh begin 573*ca987d46SWarner Losh dup menuset_x tuck c! 1 s" x" setenv \ set $x to x 574*ca987d46SWarner Losh 575*ca987d46SWarner Losh s" set var=caption" evaluate 576*ca987d46SWarner Losh menuset-unloadmenuxvar 577*ca987d46SWarner Losh menuset-unloadmenuxvar 578*ca987d46SWarner Losh menuset-unloadansixvar 579*ca987d46SWarner Losh [char] 0 ( n x -- n x y ) \ Inner loop '0' to '9' 580*ca987d46SWarner Losh begin 581*ca987d46SWarner Losh dup menuset_y tuck c! 1 s" y" setenv 582*ca987d46SWarner Losh \ sets $y to y 583*ca987d46SWarner Losh menuset-unloadmenuxyvar 584*ca987d46SWarner Losh menuset-unloadansixyvar 585*ca987d46SWarner Losh 1+ dup 57 > ( n x y -- n x y' 0|-1 ) 586*ca987d46SWarner Losh until 587*ca987d46SWarner Losh drop ( n x y -- n x ) 588*ca987d46SWarner Losh s" set var=command" evaluate menuset-unloadmenuxvar 589*ca987d46SWarner Losh s" set var=init" evaluate menuset-unloadmenuxvar 590*ca987d46SWarner Losh s" set var=keycode" evaluate menuset-unloadmenuxvar 591*ca987d46SWarner Losh s" set var=text" evaluate menuset-unloadtoggledxvar 592*ca987d46SWarner Losh s" set var=ansi" evaluate menuset-unloadtoggledxvar 593*ca987d46SWarner Losh 594*ca987d46SWarner Losh 1+ dup 56 > ( x -- x' 0|-1 ) \ increment and test 595*ca987d46SWarner Losh until 596*ca987d46SWarner Losh drop ( n x -- n ) \ loop iterator 597*ca987d46SWarner Losh 598*ca987d46SWarner Losh s" set var=acpi" evaluate menuset-unloadmenuvar 599*ca987d46SWarner Losh s" set var=init" evaluate menuset-unloadmenuvar 600*ca987d46SWarner Losh s" set var=kernel" evaluate menuset-unloadmenuvar 601*ca987d46SWarner Losh s" set var=options" evaluate menuset-unloadmenuvar 602*ca987d46SWarner Losh s" set var=optionstext" evaluate menuset-unloadmenuvar 603*ca987d46SWarner Losh s" set var=reboot" evaluate menuset-unloadmenuvar 604*ca987d46SWarner Losh 605*ca987d46SWarner Losh 1+ dup 65535 > ( n -- n' 0|-1 ) \ increment and test 606*ca987d46SWarner Losh until 607*ca987d46SWarner Losh drop ( n' -- ) \ loop iterator 608*ca987d46SWarner Losh 609*ca987d46SWarner Losh s" buf" unsetenv 610*ca987d46SWarner Losh menuset-cleanup 611*ca987d46SWarner Losh; 612*ca987d46SWarner Losh 613*ca987d46SWarner Loshonly forth definitions 614*ca987d46SWarner Losh 615*ca987d46SWarner Losh: menuset-loadinitial ( -- ) 616*ca987d46SWarner Losh s" menuset_initial" getenv dup -1 <> if 617*ca987d46SWarner Losh ?number 0<> if 618*ca987d46SWarner Losh menuset-loadsetnum 619*ca987d46SWarner Losh then 620*ca987d46SWarner Losh else 621*ca987d46SWarner Losh drop \ cruft 622*ca987d46SWarner Losh then 623*ca987d46SWarner Losh; 624