code revised 10/27/2016 - added plus symbol to /b switch for 2-column wide border verticals
This batch script should be good for a few minutes of amazement.
If there is not yet a checkboard generator, here it is.
If there are any glitches, I'll fix it.
A day of diversion while plodding along with release 2 of mega-FrameTool.
Aacini's colorshow.exe made it all possible.
Enjoy
cboard.bat:
Code: Select all
@Echo Off
setlocal EnableDelayedExpansion
@:
@: Batch script builds a string of parameters from batch arguments
@: to display checkered and patterned boards with ColorShow.exe.
@:
@: The following codes with their parameters are entered from the command-line
@: and must be preceded by a forward slash:
@:
@: a = across # of squares, min=2, max=30, default=2: /a5
@: d = down # of squares, min=1, max=30, default=2: /d4
@: w = width of square, max=16, default=1: /w6
@: h = height of square, # of lines, max=16, default=1: /h3
@: c = color of alternate squares background, default=78: /ce1 (yellow square, blue square, ...)
@: c..:.. = alternate squares b/f colors if filler ascii code(s) entered: /ce4:1b 178:177
@: b = border b/f colors, default=87: /b08 (/b00=black border)
@: b.+ = border verticals 2 columns wide with solid color: /be+
@: bxx = no border: /bxx
@: i = indent # columns, max=60, default=0: /i3
@:
@: No forward slash for this optional entry:
@: ###:### = ascii codes in range 1-255 as fillers (default=32:32): 177:178
@:
@: notes:
@: command-line entries are accepted in any order.
@:
@: Entries exceeding the maximum will be adjusted to the maximum allowed.
@:
@: When 2 ascii codes are entered as fillers, 2 sets of unique color codes are needed
@: to produce a checkered effect: /c1f:4b 178:177
@:
@: Enter ? to view this information.
@:
:: examples:
::: /a2 /d1 /w20 /h8 /ce4 /b0e /i1
::: /a8 /d8 /w6 /h2 /cf0 /b07 /i6
::: /a4 /d4 /w6 /h2 /c2a /b67 /i1
::: /h6 /w12 /a3 /d3 /c1b /b08 /i4
::: /h5 /w10 /a5 /d4 /c2c:4e 221:178 /b47 /i2
::: /a4 /d4 /w9 /h4 /c26:f1 /i1 /b01 176:177
::: /a7 /d5 /w9 /h2 /c5b:8c /b8c 176:178
::: /a17 /d14 /w3 /h1 /ca4:a4 /b2a 179:177 /i6
::: /a20 /d8 /w1 /h1 /ce0:1f 15:197 /b2+ /i20
::: /a3 /d3 /w5 /h2 /cf1:0c 178:176 /b00 /i1
::: /a12 /d10 /w4 /h2 /c36:1d /bc+ /i1 219
::: /a8 /d10 /w9 /h2 /cf8:e2 /bxx /i2 219:219
::: /a20 /d16 /w3 /h1 /c6b:20 /b67 179:223 /i2
::: /a7 /d5 /w10 /h4 /cb0:23 /b2+ 206:254 /i4
::: /a3 /d3 /w11 /h5 /c4c:af /i1 /b22 220:220
::: /a7 /d4 /w5 /h2 /cbf:51 /i1 /bcc 177:178
::: /a15 /d10 /w5 /h2 /cc0 /bab /i2
::: /a9 /d9 /w5 /h2 /c28:ac /i1 /b00 176:178
::: /a22 /d22 /w2 /h1 /c5e /b2e /i2
::: /a2 /d2 /w7 /h3 /c04:e2 /b22 178
::: /a3 /d2 /w16 /h6 /c4b:76 179:176 /b2 /i4
::: /a4 /d4 /cce:4f 196:197 /b11 /i8
::: /a5 /d2 /w16 /h1 /b66 /cfc:42 /i1 254:223
::: /a19 /d16 /w2 /h1 /c5b:03 197:222 /bxx /i8
::: /a3 /d3 /w7 /h3 /cce /b1d /i1 197:196
::: /a3 /d3 /w9 /h4 /c0e:e1 /i1 /bee 176:197
::: /a25 /d20 /w3 /h1 /cec:b8 /b8+ /i2 221:254
::: /a6 /d6 /w8 /h3 /c60 /b2+ /i3
::: /a10 /d5 /w6 /h2 /cc0:f0 /b00 /i3 178:219
::: /a16 /d14 /w3 /h1 /c14:7f /bxx /i2 219:223
::: /a10 /d10 /w5 /h2 /c38:ea /i1 /b00 176:178
::
If not EXIST ColorShow.exe Echo The file colorshow.exe was not found in this folder. Exiting.& GoTo:eof
Set "str=%*" & Set "params="
If "%str%"=="" (
Set "prg=%~n0"
colorshow /0b " This batch script generates checkerd and patterened boards. Enter " /0e "!prg! ?" /0b " for details." 13 10
Set "str=/i30 32:32")
If "%str%"=="?" Call :showSamples & GoTo:eof
If not "%str%"=="!str:/=!" Set "str=/i0 %str%"
Call :getParams "%str%" retVars
For /F "tokens=1-11 delims=," %%a In ("%retVars%") Do (
Set "across=%%a" & Set "down=%%b"
Set "sqWidth=%%c" & Set "sqHeight=%%d"
Set "c1=%%e" & Set "c2=%%f"
Set "bdrColors=%%g" & Set "indent=%%h"
Set "ascii1=%%i" & Set "ascii2=%%j" & Set "vertWide=%%k")
If "%ascii1%%ascii2%"=="3232" (
rem solid colors will be displayed
Set "color1=%c2:~1,1%" & Set "color2=%c2:~0,1%"
Set "color1=!color1!!color1!" & Set "color2=!color2!!color2!"
) Else (Set "color1=%c1%" & Set "color2=%c2%")
If "%vertWide%"=="TRUE" (
Set "bdrColors=%bdrColors:~0,1%%bdrColors:~0,1%"
Set "vertChar=32*2"
) Else (Set "vertChar=179")
If %indent% gtr 0 Set "indentStr=/07 32*%indent%"
If not "%bdrColors%"=="XX" (
Set "VTL=%indentStr% /%bdrColors% %vertChar%"
Set "VTR=/%bdrColors% %vertChar%"
If "%vertWide%"=="TRUE" (
Set "UL=32*2" & Set "UR=32*2" & Set "HZ=32"
) Else (Set "UL=218" & Set "UR=191" & Set "HZ=196")
If "%vertWide%"=="TRUE" (
Set "LL=32*2" & Set "LR=32*2"
) Else (Set "LL=192" & Set "LR=217")
Set /A "bdrHZLen=%across%*%sqWidth%"
Set "params=13 10 %indentStr% /%bdrColors% !UL! !HZ!*!bdrHZLen! !UR! 13 10"
) Else (
Set "params=13 10"
If %indent% gtr 0 Set "VTL=%indentStr%")
rem build the string of parameters for colorshow.exe that defines the board
Set "length=0"
For /L %%r In (1,1,%down%) Do (
Set /A "n=%%r%%2"
If !n! equ 0 (
Set "c1=%color1%" & Set "c2=%color2%"
) Else (
Set "c1=%color2%" & Set "c2=%color1%")
For /L %%s In (1,1,%sqHeight%) Do (
Set "z=0"
Set "params=!params! %VTL%"
For /L %%t In (1,1,%across%) Do (
If !z! lss %across% Set "params=!params!/!c1! %ascii1%*%sqWidth%"
Set /A "z+=2"
If !z! leq %across% Set "params=!params!/!c2! %ascii2%*%sqWidth%"
)
Set "params=!params! %VTR% 13 10")
rem reduce space in params string
Set "params=!params: = !"
Set "params=!params: /=/!"
Call Call :lengthCalc "%%params:~!length!%%" lengthOf & Set /A "length+=!lengthOf!"
If !length! gtr 7600 (
rem params length may exceed what a variable can store. do colorshow in part.
ColorShow !params!
Set "params=" & Set "length=0"))
If not "%bdrColors%"=="XX" (
Set "params=%params% %indentStr% /%bdrColors% %LL% %HZ%*%bdrHZLen% %LR% 13 10")
If defined params ColorShow %params%
endlocal & exit /b
rem __________________________ functions begin here ___________________________
:getParams [command-line entries] [returm var: comma-delimited string of all parameters]
rem assign variables according to switches and settings entered on the command-line.
rem assign default setting if value missing or invalid number.
setlocal EnableDelayedExpansion
Set "args=%~1"
Set "args=!args:/= /!"
Set "args=!args: /= /!"
If "!args:~0,1!"==" " Set "args=!args:~1!"
Set "args=%args:,=:%"
Set "args=%args:;=:%"
Call :upperCase "%args%" args
rem assign defaults: square height & width, # across & # down,
rem squares colors, border colors, # of indented columns
Set "adef=2" & Set "ddef=2"
Set "hdef=4" & Set "wdef=8"
Set "cdef=78" & Set "bdef=87" & Set "idef=0"
rem assign limits to vars:
Set "almt=30" & Set "dlmt=30"
Set "hlmt=16" & Set "wlmt=16" & Set "ilmt=60"
If not "%args%"=="!args:~/=!" (
For %%t In (%args%) Do (
Set "sw=%%t"
If "!sw:~0,1!"=="/" (
If "!sw:~0,2!"=="/A" Set "a=!sw:~2!"
If "!sw:~0,2!"=="/D" Set "d=!sw:~2!"
If "!sw:~0,2!"=="/H" Set "h=!sw:~2!"
If "!sw:~0,2!"=="/W" Set "w=!sw:~2!"
If "!sw:~0,2!"=="/C" Set "c=!sw:~2!"
If "!sw:~0,2!"=="/B" Set "b=!sw:~2!" & Set "border=TRUE"
If "!sw:~0,2!"=="/I" Set "i=!sw:~2!"
) Else (
rem look for 1 or 2 ascii codes entered for fill characters
For %%n In (!sw!) Do (
If "!asciiCode1!"=="" (
Call :asciiValidate "%%n" asciiCode1 asciiCode2))
))
rem validate numeric entries; set to default if invalid or to maximum if limit exceeded
For %%o In (a d h w i) Do (
Call :numComponent "!%%o!" %%o
If not defined %%o Set "%%o=!%%odef!"
If !%%o! gtr !%%olmt! Set "%%o=!%%olmt!")
rem set square & border colors to defaults if missing from command-line entry
For %%o In (c b) Do If not defined %%o Set "%%o=!%%odef!")
If "%b%"=="" If "%border%"=="TRUE" Set "b=87"
If "%b%"=="+" Set "b=8+"
If not "%b%"=="%b:XX=%" (
Set "vWide=FALSE"
) Else (
If not "%b%"=="%b:+=%" (
Set "vWide=TRUE" & rem border verticals will be 2 columns wide
Set "b=%b:+=%"
Set "b=!b:~0,1!" & rem remove 2nd color code if it was there
) Else (Set "vWide=FALSE"))
rem if 2 sets of color codes were entered, break out into 2 vars,
rem otherwise assign the same color codes to the 2 vars.
If not "%c%"=="!c::=!" (
For /F "tokens=1,2 delims=:" %%m In ("%c%") Do (
Set "colorCodes1=%%m" & Set "colorCodes2=%%n")
) Else (Set "colorCodes1=%c%" & Set "colorCodes2=%c%")
rem assign default values to parameters not defined
For %%o In (a d w h i) Do If not defined %%o Set "%%o=!%%odef!"
rem these vars can not be 0
For %%o In (a d w h) Do If "!%%o!"=="0" Set "%%o=!%%odef!"
If %a% lss 2 Set "a=2" & rem across minimum is 2
If not defined asciiCode1 Set "asciiCode1=32"
If not defined asciiCode2 Set "asciiCode2=32"
Set "parmsStr=%a%,%d%,%w%,%h%,%colorCodes1%,%colorCodes2%,%b%,%i%,%asciiCode1%,%asciiCode2%,%vWide%"
endlocal & set "%~2=%parmsStr%" & exit /b
rem ______________________________ end getParams ______________________________
:upperCase
rem convert letters in %1 to uppercase. assign converted string to %2
setlocal EnableDelayedExpansion
For /F "delims=" %%a In ("%~1") Do (
Set "chars=%%a"
For %%b In (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do (
Set "chars=!chars:%%b=%%b!"
))
endlocal & set "%~2=%chars%" & exit /b
rem ______________________________ end upperCase ______________________________
:numComponent [string] [return var]
rem return numeric component at trailing end of string or return 0.
setlocal
Set "chars=%~1"
Set "chars=%chars: =%"
Set "validChars=0 1 2 3 4 5 6 7 8 9"
Set "numbs="
rem save numeric characters at end of string until non-numeric char is found.
:topNC
Set "numer="
Set "temp=%chars:~-1%"
For %%i In (%validChars%) Do If "%temp%"=="%%i" Set "numer=%%i" & GoTo:nextNC
:nextNC
If not "%numer%"=="" (Set "numbs=%numer%%numbs%") Else GoTo:endNC
Set "chars=%chars:~0,-1%"
GoTo:topNC
:endNC
If "%numbs%"=="" Set "numbs=0"
Set /A "numbs=%numbs%*1" & rem this would remove leading 0
endlocal & set "%~2=%numbs%" & exit /b
rem ______________________________ end numComponent ___________________________
:asciiValidate [string to validate] [ret var ascii code #1] [ret var ascii code #2]
rem validate %1 for numeric value or two delimited values in the range 1-255.
setlocal EnableDelayedExpansion
Set "str=%~1"
For /F "tokens=1* delims=:" %%a In ("%str%") Do Set "val1=%%a" & Set "val2=%%b"
Call :numComponent "%val1%" val1
If not "%val2%"=="" Call :numComponent "%val2%" val2
If "%val2%"=="" (Set "loopCount=1") Else Set "loopCount=2"
For /L %%n In (1,1,%loopCount%) Do (
Set "var=val%%n"
Set /A "x=!val%%n!"
If !x! lss 1 (
Set "!var!=1"
) Else If !x! gtr 255 (
Set "!var!=255"))
rem if ascii code # is restricted, change it to code #32 (a blank)
For /L %%n In (1,1,%loopCount%) Do (
For %%c In (7 8 9 10 13) Do If %%c equ !val%%n! Set "val%%n=32"
)
If "%val2%"=="" Set "val2=32"
endlocal & Set "%~2=%val1%" & Set "%~3=%val2%" & exit /b
rem ______________________________ end asciiValidate __________________________
:lengthCalc
rem lengths will be accumulated to calculate length of parameters string.
setlocal EnableDelayedExpansion
Set "tmpfile=temp.tmp"
>"%tmpfile%" echo %~1
Set "length=0"
For /F "usebackq" %%I In ('%tmpfile%') Do Set /A "length=%%~zI-2"
If EXIST temp.tmp DEL temp.tmp
endlocal & Set "%~2=%length%" & exit /b
rem:_______________________________end lengthCalc______________________________
:showSamples
setlocal EnableDelayedExpansion
Set "count=0"
for /f "tokens=1,* delims=@:" %%a in ('findstr /bn "@:" "%~f0" ') do (
Set "line=%%b"
If "!line!"=="" Set "line= "
Set "arrayTxt[!count!]=!line!"
Set /A "count+=1")
Set /A "count-=1"
For /L %%n In (1, 1, %count%) Do (
colorshow /0e arrayTxt[%%n] 13 10)
colorshow 13 10 /0b " Press Enter to view samples, or Ctrl+C to halt the batch file." 13 10
pause>nul
for /f "tokens=1,* delims=:::" %%a in ('findstr /bn ":::" "%~f0" ') do (
Set "line=%%b"
colorshow /0f "!line!" 13 10 & Call %~f0 !line! & pause)
endlocal & exit /b
rem ______________________________ end showSamples_____________________________