Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @REM this script demonstrates the use of my fast performing Mirror macro to output symetrical ASCII art.
- @Cls & @Call:DefMirror
- @If errorlevel 1 @(
- @Call:Defmirror "/?"
- @Exit/b
- )
- @rem usage example: Eye of providence.
- %Mirror% " ^"," `/~"," ``/(@@"," .`<---"," ``'*"," /"""""""""," /; "," /; "," /; ","<---@MDCCLXXVI"
- @Rem example macro repetition features
- @Pause > nul
- @Cls
- %Mirror:#=2% " ^[4]"," `/~[4]"," ``/(@@[4]"," .`<---[4]"," ``'*[4]"," /""""""""[4]"," /; [4]"," /; [4]"," /; [4]","<---@MDCCLXXVI[4]","{1} "
- %Mirror% "-[69]"
- %Mirror% "[14] '-{3}"
- @Rem Demonstrate non alhpanum character support and escaping. Escaped ! requires ^ to also be ^^^ escaped
- %Mirror% "^^^^ ~^^^!@@#$%%&*()_+=-\|]}[{`';:/?.><"""
- @Pause > nul
- %Mirror:#=3% " ^[5]"," / [5]","/ M[5]" /F
- @Pause > nul
- @Rem demonstrate speed of macro. 1000 * 10 horizontal = 10,000 repeats
- @Rem execution time [ machine specs will cause varying results ] : ~ 14 seconds : Total of ~ 700 repeats/second
- %Mirror:#=1000% "[10] (--","[10] \~","[10] X","[10] /~"
- @Goto:Eof
- :: ===================== | Mirror MACRO Definition. Author - T3RRY | =====================
- :DefMirror USAGE:
- :: *** Version changes 11/11/2021:
- :: /F 'Flip' switch added. Mirrors pattern vertically.
- :: *** Version changes 9/11/2021:
- :: [Int] and {Int} partial repetition subargs may now be interchangeably positioned at string left or right.
- :: Doublequote is now escaped with itself: "" to print " - Each paired " is substituted to `DQ` before string processing.
- :: Multiple linefeeds may now be effected using %Mirror% "{Int}"
- :: Usage examples and help info updated to reflect changes.
- ::
- :: Call :DefMirror ["/?"]|[Int]
- :: "/?" This help info.
- :: Int - Overrides default max string length [ Default = 50 characters per "string" ]
- ::
- :: Mirror Macro Usage:
- :: %Mirror% "string" [/F]
- :: %Mirror% "string" "otherstring" [/F]
- :: %Mirror% "string","otherstring" [/F]
- :: %Mirror% "string", "otherstring" [/F]
- :: %Mirror% "string" , "otherstring" [/F]
- ::
- :: Whole Pattern repetition:
- :: Repeat the whole Pattern Int number of times:
- :: %Mirror:#=Int% "String","OtherString"
- ::
- :: Partial Pattern repetition:
- :: %Mirror% "string[Int]" or "[Int]string" ; Where Int is a number [1-99]: Repeat mirrored string Int times Horizontally.
- :: %Mirror% "string{Int}" or "{Int}string ; Where Int is a number [1-99]: Repeat mirrored string Int times Vertically.
- :: ** Repetition features may be combined: %Mirror:#=2% "{Int}string[Int]" or %Mirror:#=2% "[Int]string{Int}"
- :: ** Strings beginning / ending with {Int} or [Int] ALWAYS trigger this behaviour If Int is GTR 0 LSS 100.
- ::
- :: Additional Info:
- :: ** Delayed expansion must NOT be enabled prior to calling DefMirror
- :: ** Delayed expansion is toggled on/off by %Mirror% macro and is NOT REQUIRED to be enabled prior to expansion the macro.
- :: ** Mirror macro does not require echo state to be off, and expands in it's own local environment.
- :: - 'Reverse*CHAR' 'Flip*CHAR' '_Hash' and 'LF' variables are defined in the calling scripts environment.
- :: ** Macro args MUST be doublequoted if multiple args are supplied, failure to doublequote will result in
- :: the string being treated as a single arg and may cause unexpected behaviour if the string contains poison characters.
- :: ** A temporary file is used to facilitate handling of `*` character, which cannot be handled directly in a for loop.
- :: ** Calling :DefMirror with a MaxLength Shorter than a supplied strings length will result in the macro hanging.
- :: ** To print a newline using the macro, The string value must contain 2 or more whitespaces: " "
- :: To print multiple newlines: "{Int}" ; Where Int is number GTR 0 LSS 100
- ::
- :: Supports all ASCII Characters, Observing the following usage information and ESCAPING Requirements:
- :: - ; Is reserved as a shading character - It will print on the left hand side of the string, and be replaced
- :: with a whitespace on the right.
- :: - @ is reserved for signalling the end of mirroring. Text following @ is printed between mirrored text.
- :: to use @ literally, escape it with itself: @@ [note: doing so will result in all text following @@ being mirrored.]
- :: - To print a doublequote, escape it with itself: "str""ing" will print: str"inggni"rts
- :: - ! must be triple escaped: ^^^!
- :: - /F Switch is incompatable with !, even when escaped.
- :: - Any string containing ^^^! will require literal carets to also be triple escaped:
- :: IE: "^^^^Hello, World^^^! " to print: "^Hello, World! !dlroW ,olleH^"
- :: - % must be escaped: %%
- @Echo("%~1" | findstr /lic:"/?" && @("%__APPDIR__%Findstr.exe" /blic:"::" "%~f0" | more && Exit/b)
- @If "!!"=="" @(Echo(Delayed expansion not permitted prior to macro definition.& @Pause & @Exit/b 1)
- @Set "_Hash=#"
- @(Set LF=^
- %= LF Linefeed variable Used in macro. Do not Modify. =%)
- @For %%G in ("(=)" ")=(" "[=]" "]=[" "{=}" "}={" "/=\" "\=/")Do @Set "Replace%%~G"
- @For %%G in ("M=W" "W=M" "6=9" "9=6" "v=^" "^=v")Do @Set "Flip%%~G"
- @Set "_EX=^!"
- @Set "Replace>=<"
- @Set "Replace<=>"
- @Setlocal
- @Set "MaxLen=0"
- @For %%G in (%*)Do @Set/A "MaxLen=%%~G" 2> nul || @Set "MaxLen=50"
- @If %MaxLen% LEQ 0 @Set "MaxLen=50"
- @(Set \n=^^^
- %= \n Newline variable for macro definition. Do not Modify =%)
- @Endlocal & @Set Mirror=@For %%v in (1 2)Do @if %%v==2 (%\n%
- @If Defined Mirror.Input (%\n%
- @Set "[F]="%\n%
- @If /I "!Mirror.Input:~-3!"==" /F" @(%\n%
- @Set "Mirror.Input=!Mirror.Input:~0,-3!"%\n%
- @Set "[F]=true"%\n%
- )%\n%
- @Set "#="%\n: Undefined in local environment to ensure no false positives below =%
- @If not "!_Hash!"=="#" @(Set /A "1 / #" 2^> nul ^&^& (@Set "_Repeat=#") ^|^| @Set "_Repeat=1")Else @Set _Repeat=1%\n%
- @For /l %%T in (1 1 !_Repeat!)Do @(%\n: Repeat entire pattern from args list. For loop input will repeated each input. =%
- @Set "_F="%\n%
- @Set "Mirror.Input=!Mirror.Input:*"="!"%\n: Strip leading characters that precede first doublequote =%
- @Set "Mirror.Input=!Mirror.Input:""=`DQ`!"%\n: Enact temp Substitution of Escaped Doublequotes =%
- @For %%G in ("!LF!")Do @(%\n: Delim args with a newline prior to outputting to file. =%
- @Set "Mirror.Input=!Mirror.Input:" , "=%%G!"%\n%
- @Set "Mirror.Input=!Mirror.Input:", "=%%G!"%\n%
- @Set "Mirror.Input=!Mirror.Input:","=%%G!"%\n%
- @Set "Mirror.Input=!Mirror.Input:" "=%%G!"%\n%
- )%\n%
- ^>"%~dpn0_In.~tmp" (Echo(!Mirror.Input!)%\n: Output prepared args to allow processing of all ASCII characters. =%
- @For /f "usebackq Delims=" %%G in ("%~dpn0_In.~tmp")Do @(%\n: Read and process args line by line =%
- @Set "_P="%\n: nul var used to Flag escaping of @ character =%
- @Set "_S="%\n: nul Arg output var =%
- @Set "_V=%%~G"%\n: Define Arg string =%
- @Set/A"_Y=_X=1"%\n: Define default Horizontal and vertical Arg repeat counts =%
- @Set ^"_V=!_V:"=!"%\n: Strip Doublequotes from Arg =%
- @Rem %\n: Begin Assessment and flagging of [Int] X {Int} Y Partial repetition subargs =%
- @Set /A 1 / !_V:~1,1! 2^> nul ^&^& @If "!_V:~0,1!!_V:~2,1!"=="{}" (%\n%
- @Set "_Y=!_V:~1,1!"%\n%
- @Set "_V=!_V:~3,%MaxLen%!"%\n%
- )Else @If "!_V:~0,1!!_V:~2,1!"=="[]" (%\n%
- @Set "_X=!_V:~-1,1!"%\n%
- @Set "_V=!_V:~1,1!"%\n%
- )%\n%
- @Set /A 1 / !_V:~1,2! 2^> nul ^&^& @If "!_V:~0,1!!_V:~3,1!"=="{}" (%\n%
- @Set "_Y=!_V:~1,2!"%\n%
- @Set "_V=!_V:~4,%MaxLen%!"%\n%
- )Else @If "!_V:~0,1!!_V:~3,1!"=="[]" (%\n%
- @Set "_X=!_V:~1,2!"%\n%
- @Set "_V=!_V:~4,%MaxLen%!"%\n%
- )%\n%
- @Set /A 1 / !_V:~-2,1! 2^> nul ^&^& @If "!_V:~-3,1!!_V:~-1!"=="[]" (%\n%
- @Set "_X=!_V:~-2,1!"%\n%
- @Set "_V=!_V:~0,-3!"%\n%
- )Else @If "!_V:~-3,1!!_V:~-1!"=="{}" (%\n%
- @Set "_Y=!_V:~-2,1!"%\n%
- @Set "_V=!_V:~0,-3!"%\n%
- )%\n%
- @Set /A 1 / !_V:~-3,2! 2^> nul ^&^& @If "!_V:~-4,1!!_V:~-1!"=="[]" (%\n%
- @Set "_X=!_V:~-3,2!"%\n%
- @Set "_V=!_V:~0,-4!"%\n%
- )Else @If "!_V:~-4,1!!_V:~-1!"=="{}" (%\n%
- @Set "_Y=!_V:~-3,2!"%\n%
- @Set "_V=!_V:~0,-4!"%\n%
- )%\n: Next Line enacts escaping of @@ or splitting of Mirror / nonmirrored substrings =%
- @If "!_V:@@=!"=="!_V!" (@For /f "tokens=1,2 Delims=@" %%G in ("!_V!")Do @Set "_V=%%~G"^&@set "_P=%%~H")Else @If defined _V @set "_V=!_V:@@=@!"%\n%
- @If defined _V @Set ^"_V=!_V:`DQ`="!"%\n: enacts substitution to reinsert doublequotes =%
- @Set "_I="%\n: nul string length variables =%
- @Set "_Pi="%\n: Next line gets full string length =%
- @For /l %%i in (0 1 %MaxLen%)Do @If not defined _I @If "!_V:~%%i!"=="" @Set/A"_I=%%i,_O=%%i-2" 2^> nul%\n%
- @If defined _P (%\n: Get offset length if @ used to split substring =%
- @For /l %%i in (0 1 %MaxLen%)Do @If not defined _Pi @If "!_P:~%%i!"=="" @Set/A"_Pi=%%i"%\n%
- @Set /A _O=_Pi-_O%\n%
- )%\n%
- @If Defined _V @For /l %%i in (0 1 !_I!)Do @Set "_S=!_S!!_V:~%%i,1!"%\n: Build Left half of output string =%
- @Set "_S=!_S!!_P!"%\n: Append unmirrored component if defined =%
- @For /l %%i in (!_O! -1 0)Do @(%\n: Append mirror of string enacting replacements =%
- @If "!_V:~%%i,1!"==";" @Set "_S=!_S! "%\n%
- @For /f "delims=" %%v in ("!_V:~%%i,1!")Do @(If not "!Replace%%v!"=="" @(Set "_S=!_S!!Replace%%v!")Else @Set "_S=!_S!!_V:~%%i,1!")%\n%
- )%\n%
- @Set "_M="%\n: nul _M var used to join horizontal repetitions =%
- @For /l %%i in (1 1 !_X!)Do @Set "_M=!_M!!_S!"%\n: append horizontal repetitions =%
- @If Defined _M @Set "_S=!_M!"%\n: Swap out appended string if defined =%
- @Set "_Fc="%\n%
- @If Defined [F] @For /l %%i in (0 1 %MaxLen%)Do @If not "!_S:~%%i,1!"=="" @(%\n: define vertical mirror of substring enacting replacements =%
- @For /f "delims=" %%v in ("!_S:~%%i,1!")Do @(If not "!Replace%%v!"=="" @(Set "_Fc=!_Fc!!Replace%%v!")Else @If not "!Flip%%v!"=="" @(Set "_Fc=!_Fc!!Flip%%v!")Else (@Set "_Fc=!_Fc!!_S:~%%i,1!"))%\n%
- )%\n%
- @For /l %%i in (1 1 !_Y!)Do @(%\n%
- @Echo(!_S!%\n: repeat string vertically =%
- )%\n%
- @If Defined [F] @(@If not Defined _F @(@Set "_F=!_Fc!")Else @Set "_F=!_Fc!!LF!!_F!")%\n: Append vertical Mirror =%
- )%\n%
- @If Defined [F] @Echo(!_F!%\n%
- @Del "%~dpn0_In.~tmp" 2^> nul%\n%
- )%\n: remove the temp file used. =%
- @Endlocal%\n: Ends the local environment if args supplied. =%
- )Else @Endlocal%\n: Ends the local environment if no args supplied to macro. =%
- )Else @Setlocal ENableDelayedExpansion ^& @Set Mirror.Input=
- @Exit /b 0
Add Comment
Please, Sign In to add comment