Advertisement
T3RRYT3RR0R

Esolang BatchStax v2.4.1

Dec 21st, 2021 (edited)
1,647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 39.27 KB | None | 0 0
  1. <# : batch portion
  2. :# The above line marks the beginning of a powershell comment block; and the Batch component of the Script. Do not modify.
  3. @Echo off
  4.  
  5.  Setlocal ENABLEextensions ENABLEdelayedexpansion
  6.  Set "PS.Utility=For %%n in (1 2)Do if %%n==2 (Echo/^^^!Args:~1^^^!| powershell.exe -noprofile "$Mode = $input ^| ?{$_}; iex (${%~f0} ^| out-string)")Else Set Args="
  7. :# Toggle Fullscreen by calling powershell component of script.
  8. If not defined fscreen %PS.Utility%
  9.  
  10. Endlocal & Set "fscreen=true"
  11. :::::::::::::::::::::::::::::::::::::::::::::: REM TBA script readability review.
  12. REM Esolang: BatchStax by T3RRY ; loosely based off isdo. See syntax for valid operations.
  13.  
  14. REM This esolang now supports runtime inputs.
  15. REM Input Arguments may reference preceeding arguments as an Arithemetic expression - See Syntax for more info.
  16. REM
  17. REM NOTE: .bs Programs Should be located in the same directory tree as this Interpreter.
  18. REM IMPORTANT NOTE: Command lines terminating in .bs will be treated as being a path for a .bs script
  19. REM                 - this 3 digit string would otherwise be a valid, if unlikely command sequence
  20. REM This script is an interpreter for BatchStax, and includes limited debugging tools and error checking.
  21. ::: Version 2.4.1
  22. REM Version Change 24/05/2023: Added VT Command: "5" - Subsequent output will be in blinking mode. Pre-existing command: "~" resets cursor graphics mode
  23. REM                            Added shorthand: "£" - equivelant f#a
  24. REM                            
  25. REM VERSION Change 04/01/2022: Corrected literal String parsing to facilitate literal output of `*` character [special meaning in for loops.]
  26. REM                            Expanded character output support to include utf characters in the range 1~239 of code page 65001
  27. REM                            UTF8 Character indexing method significantly faster than previous ASCII character indexing method.
  28. REM VERSION Change 03/01/2022: Support added for USER input/s to commands at runtime via Arguments. See Updated Syntax and included example.
  29. REM VERSION Change 02/01/2022: Support added for Integer input to commands via Arguments. Inputs may be referenced in loop repeat arguments,
  30. REM                            stack array assingments or by subsequent input arguments.
  31. REM                            IMPORTANT: In the event command arguments are used, All instances of the String $_index, where index is
  32. REM                            an Integer within the maximum number of arguments supplied will be replaced with the relevant Argument.
  33. REM                            $_1 $_2 $_4 $_6 $_7 and $_8 would otherwise be valid, if unlikely, command sequences.
  34. REM VERSION Change 01/01/2022: Nested loop parsing and command error output extensively improved.
  35. REM                            Supports any nested loop structure with appropriately balanced
  36. REM                            parentheses and ':' seperators, provided each loop terminates with ':Integer)'
  37. REM                            Added support for Literal string output
  38. REM                            Added escaping rule for literal output of parentheses
  39. REM                            Prohibits literal use of strings: '//O' and '//C'
  40. REM                            '~' Virtual Terminal command added
  41. REM                              - Resets foreground / background color if Virtual Terminal sequences supported.
  42. REM
  43. ::: Version 2.0 : Breaking change introduced since last version for command lines containing 'Q'
  44. REM VERSION Change 23/12/2021: Added requirement for source scripts to have .bs extension to facilitate
  45. REM                            golfing quines.
  46. REM                             - Added Golf quines. If any commandline or script consists of
  47. REM                            a single command, the literal command character will be output.
  48. REM VERSION Change 22/12/2021: Command 'Q' now terminates program if the Current stack value EQU rVal
  49. REM                            - Previous behavior was to output 1 or 0 if true or false
  50. REM VERSION Change 21/12/2021: Added LIMITED support for Nested loops - See updated Syntax.
  51. REM                            - Infinite loops Are NOT supported.
  52. REM                            Added option of calling interpreter with a filepath containing source code.
  53. REM                             instead of calling with Command line arguments. The interpreter will pause
  54. REM                             and wait for a keypress after each line has executed.
  55. REM                             ** Note:
  56. REM                              Each line is treated as a new script. stack values and rVal do not persist.
  57. REM VERSION Change 20/12/2021: Added simple looping / repetition - See updated Syntax.
  58. REM VERSION Change 19/12/2021: Now accepts Input argument to predefine stack value / stack array values and
  59. REM                            assign initial stack. - See updated Syntax
  60. REM                            - Removed Virtual terminal Color command 'E', replaced with
  61. REM                              'B' [background] and added 'F' [foreground]
  62. REM VERSION Change 18/12/2021: New Virtual terminal features:
  63. REM                            - Cursor left right up down
  64. REM                            - Background color change
  65. REM Creative Commomns License 4.0
  66. REM https://creativecommons.org/licenses/by-nc-sa/4.0/
  67. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  68.  
  69. REM code page 65001 mandatory for this program to function as intended.
  70.  CHCP 65001 > nul
  71. REM Critical Variable definition; requires default Disabled expansion environment. character index range: 1 ~ 239
  72.  If "!!"=="" (Exit /b 1)
  73.  
  74.  Set ^"UnicodeChars= ☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø×ƒáíóúñѺ¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦▀ÓßÔÒõÕµþÞÛÙýݯ´­±‗¾"
  75.  
  76. ::====================================================================================================
  77. Rem :: input capture method is a modified version of Dave Benhams method:
  78. Rem :: https://www.dostips.com/forum/viewtopic.php?t=4288#p23980
  79. REM ** input of literal "<" and ">" characters require caret escaping. "&" and "|" characters require the input to be doublequoted.
  80.  SETLOCAL DISableDelayedExpansion
  81.   Set "CommandError="
  82.  SETLOCAL EnableDelayedExpansion
  83.  1>"%~f0:Params.dat" <"%~f0:Params.dat" (
  84.   SETLOCAL DisableExtensions
  85.   Set prompt=#
  86.   Echo on
  87.   For %%a in (%%a) do rem . %*.
  88.   Echo off
  89.   ENDLOCAL
  90.   Set /p "_="
  91.   Set /p "_="
  92.   Set "_=!_:~7,-2!"
  93.  @Rem duplicate for debug output
  94.   Set "CL=!_!"
  95.  ) || (
  96.   1>&2 Echo(%~nx0 requires an NTFS drive system to function as intended.
  97.   CMD /C Exit -1073741510
  98.  ) || Goto:Eof
  99.  
  100.  If not defined UnicodeChars (
  101.   Call:FlagError "Interpreter has been modified."
  102.   Goto:EndRun
  103.  )
  104.  For /l %%n in (1 1 239)Do Set ^"Uni[%%n]=!UnicodeChars:~%%n,1!"
  105.  
  106. REM detect help switches or empty commandline; output help.
  107.  set "_" 2>&1 | %systemroot%\system32\findstr.exe /li "\/? -? help syntax defined" > nul && (
  108.   Mode 1000
  109.   Call :Syntax
  110.   If not errorlevel 1 Pause
  111.   Goto:Eof
  112.  )
  113.  
  114. REM detect golfing help switch golfing info.
  115.  Set "Fstr=Rem"
  116.  set "_" 2>&1 | %systemroot%\system32\findstr.exe /li "\/golf" > nul && (
  117.   Mode 1000
  118.   For /F "Tokens=2* Delims=," %%G in ('%systemroot%\system32\findstr.exe /li "%Fstr%," "%~f0"')Do Echo(%%G
  119.   Pause
  120.   Endlocal & Goto:Eof
  121.  )
  122.  
  123. REM enact escaping and substitutions for safe processing.
  124.  Set "_=!_:&=^&!"
  125.  Set "_=!_:|=^|!"
  126.  Set "_=%_:!=XCLM%"
  127.  
  128. Rem a defined value to the below devmode variable logs command errors and / or output. Defined using /D switch.
  129.  Set "devmode="
  130.  If not "!_:/D=!"=="!_!" (
  131.   Set "_=!_: /D =!"
  132.   Set "_=!_:/D =!"
  133.   Set "_=!_: /D=!"
  134.   Set "_=!_:/D=!"
  135.   Set "devmode=true"
  136.  )
  137.  
  138. REM,===========================================================================================================
  139. REM,                                             Golfing shorthands
  140. Rem,
  141. Rem, Alt 0161 '¡'          - Equivalent to $_ Argument reference prefix
  142.  Set "_=!_:¡=$_!" & Set "CL=!CL:¡=$_!"
  143. Rem,
  144. Rem, Alt 223  '▀'          - Equivalent to ai ; output unicode character + increment rval
  145.  Set "_=!_:▀=ia!" & Set "CL=!CL:▀=ia!"
  146. Rem,
  147. Rem, Alt 220  '▄'          - Equivalent to ia ; increment rval + output unicode character
  148.  Set "_=!_:▄=ai!" & Set "CL=!CL:▄=ai!"
  149. Rem,
  150. Rem, Alt 0170 'ª'          - Equivalent to 44a ; outputs unicode value of rval left of previous output character
  151.  Set "_=!_:ª=44a!" & Set "CL=!CL:ª=44a!"
  152. Rem,
  153. Rem, Alt 0131 'ƒ'          - Equivalent to fa ; Change color to rval + output unicode character
  154.  Set "_=!_:ƒ=fa!" & Set "CL=!CL:ƒ=fa!"
  155. Rem,
  156. Rem, alt 156 '£'           - Equivalent to f#a ; Change color to rval + Assign value of current stack to rval + output unicode character
  157.  Set "_=!_:£=f#a!" & Set "CL=!CL:£=f#a!"
  158. Rem,
  159. REM, Alt 0191 '¿' / ?U     - Equivalent to: ?#239 - input request within supported range of unicode characters.
  160.  Set "_=!_:¿=?#239!"
  161.  Set "_=!_:?U=?#239!" %= Backwards compatability =%
  162. Rem,
  163. REM, alt 0135 '‡'
  164. REM, Enact shorthand Array syntax with IMPLICIT starting index 0:
  165. REM, Shorthand Syntax: {ArrayIntegerList;StartIndex} Becomes: ArrayIntergerList‡
  166. REM, PREREQUISITE: Arraylist to prefix command line
  167. REM, CONSTRAINTS:  { and ‡ cannot be used as literal strings
  168.  If not "!_:‡=!"=="!_!" If "!_:{=!"=="!_!" (
  169.   Set "_={!_:‡=;0}!"
  170.   Set "CL={!CL:‡=;0}!"
  171.   If not "!CL:{/D =!"=="!CL!" (
  172.    Set "CL=/D !CL:{/D ={!"
  173.   )Else If not "!CL:{/D=!"=="!CL!" (
  174.    Set "CL=/D !CL:{/D={!"
  175.  ))
  176.  
  177. Rem,
  178. REM, Alt 174 '«' and Alt 175 '»'
  179. REM, « equivalent to -# ; decrements array index ; assigns stored value at array index to the pointer
  180. REM, » equivalent to +# ; increments array index ; assigns stored value at array index to the pointer
  181. REM, CONSTRAINTS:          « and » cannot be used as literal strings
  182.  Set "_=!_:┐«=┐a«!" & Set "CL=!CL:«=-#!"
  183.  Set "_=!_:┐»=┐a»!" & Set "CL=!CL:┐»=┐a»!"
  184.  Set "_=!_:└«=└a«!" & Set "CL=!CL:└«=└a«!"
  185.  Set "_=!_:└»=└a»!" & Set "CL=!CL:└»=└a»!"
  186.  Set "_=!_:«=-#!"   & Set "CL=!CL:«=-#!"
  187.  Set "_=!_:»=+#!"   & Set "CL=!CL:»=+#!"
  188. Rem,
  189. Rem, Alt 191 '┐' and alt 192 '└'
  190. REM, ┐  equivalent to d@ ; decrements value of the pointer and stores it at the current array index
  191. REM,  └ equivalent to i@ ; increments value of the pointer and stores it at the current array index
  192. REM, CONSTRAINTS: ┐ and └ cannot be used as literal strings
  193.  Set "_=!_:┐=d@!" & Set "CL=!CL:┐=d@!"
  194.  Set "_=!_:└=i@!" & Set "CL=!CL:└=i@!"
  195. Rem,
  196. REM, IMPLICIT:           ┐« └« ┐» └» each assume output of indexed unicode character between value changes.
  197. Rem,  - Equivalents:     ┐« = d@a-#
  198. Rem,                     └« = i@a-#
  199. Rem,                     ┐» = d@a+#
  200. Rem,                     └» = i@a+#
  201. Rem,
  202. Rem, Alt 139 ï
  203. REM, ï Equivalient to ii ; increments the value held by the pointer twice
  204. REM, CONSTRAINTS: ï cannot be used in literal string
  205.  Set "_=!_:ï=ii!" & Set "CL=!CL:ï=ii!"
  206. REM,
  207. REM, EXAMPLE shorthand program: 95 64‡(i└»i└«:13)
  208. REM, prints: aBcDeFgHiJkLmNoPqRsTuVwXyZ
  209. REM,
  210. REM,===========================================================================================================
  211.  
  212. REM .bs file parsing preperation / execution.
  213.  If "!PATHEXT!"=="!PATHEXT:.bs=!"  Set "PATHEXT=!PATHEXT!;.bs"
  214.  If "!PATH!"=="!PATH:%~dp0=!" Set "PATH=!PATH!;%~dp0"
  215.  If /I "!_:~-3!"==".bs" Where *!_! 2>&1 | %SystemRoot%\System32\findstr.exe /li "pattern" > nul && (
  216.   Call:FlagError "File could not be Found."
  217.   Goto:EndRun
  218.  )
  219.  Set "BatchStaxSource="
  220.  Set "_" 2>&1 | %SystemRoot%\System32\findstr.exe /EIL ".BS" > nul && For /f "delims=" %%G in ('Where *!_! 2^> nul')Do (
  221.   Set "BatchStaxSource=%%~G"
  222.  )
  223.  If defined BatchStaxSource (
  224.   For /f "usebackQ tokens=1 Delims=\" %%G in ("!BatchStaxSource!")Do (
  225.    If "!!"=="" ENDLOCAL
  226.    Setlocal DISABLEdelayedExpansion
  227.    If not "%%~G"=="" Call "%~f0" %%G
  228.    If Errorlevel 1 (
  229.     Echo Error in Sourcefile "!BatchStaxSource!"
  230.     Pause
  231.     Exit /b
  232.    )
  233.    Endlocal
  234.   )
  235.   Endlocal
  236.   Exit /b
  237.  )
  238.  
  239. cls (Title )
  240.  
  241. Rem Define backspace to permit output of leading whitespace without newline.
  242.  For /F %%# in ('"Prompt;$H;&For %%_ in (1) Do Rem"') Do Set "\b=%%#"
  243.  
  244. :# Windows Version control for VT sequences. Assigns flag true if system is windows 10 build GTR 10586
  245. :# https://en.wikipedia.org/wiki/ANSI_escape_code#DOS,_OS/2,_and_Windows
  246. :# Version 1511 build number = 10.0.10586
  247.  Set "Win10="
  248.  For /f "tokens=3 delims=." %%v in ('Ver')Do if %%v GTR 10586 Set "Win10=True"
  249.  
  250. :# If Win10 true ; Test if virtual terminal codes enabled ; enable if false
  251. :# removes win10 flag definition if version does not support Virtual Terminal sequences
  252. :# Reg values: https://devblogs.microsoft.com/commandline/understanding-windows-console-host-settings/
  253.  If defined Win10 (
  254.   Reg Query HKCU\Console | %SystemRoot%\System32\findstr.exe /LIC:"VirtualTerminalLevel    REG_DWORD    0x1" > nul || (
  255.     Reg Add HKCU\Console /f /v VirtualTerminalLevel /t REG_DWORD /d 1
  256.   ) > Nul && (
  257.     Echo(CMD restart required to enable Virtual terminal sequences.
  258.     Pause
  259.     EXIT
  260.   ) || Set "Win10="
  261.  )
  262.  
  263.  If not defined Win10 (
  264.   Echo( Some features of this interpreter are not avialable on your system.
  265.   Echo( Output may not match expected Output where Virtual Terminal commands are used.
  266.   Timeout /T 1 /NoBreak > nul
  267.   Pause
  268.   Cls
  269.  )
  270.  If defined win10 For /f %%e in ('Echo Prompt $E^|cmd')Do Set "\E=%%e"
  271.  
  272. REM Strip doublequotes from the string prior to Substring parsing.
  273.  Set ^"_=!_:"=!"
  274.  
  275. Rem Optional input Argument Parsing. Defines an array of arguments, Substitutes all instances of arg index referenced by $_Index in commandline
  276.  Set "Arg[i]="
  277.  If not "!_:?=!"=="!_!" (
  278.   Set "Arg[i]=0"
  279.  )
  280.  If Defined Arg[i] Set "[A!Arg[i]!]=%_:?=" & Set /A "Arg[i]+=1" & Set "[A!Arg[i]!]=%"
  281.  
  282. REM removes trailing Args from command line after parsing if present.
  283.  If Defined Arg[i] Set "_=%_:?="&Rem::%
  284.  
  285.  If Defined Arg[i] For /l %%n in (1 1 !Arg[i]!)Do If defined [A%%n] (
  286.   If "![A%%n]:#=!"=="![A%%n]!" (%= Argument is prepopulated =%
  287.    For /f "UsebackQ delims=" %%v in (`CMD /C ^"Set /A "![A%%n]!"^"`)Do (
  288.     Set /a "1/%%v","1/(1/((%%v>>32)-1))" 2> nul || (
  289.       Call:FlagError "Invalid input for Argument %%n: '?![A%%n]!'='%%v'. Positive Integer Required."
  290.       Goto:EndRun
  291.     )
  292.     Set "_=!_:$_%%n=%%v!"
  293.     Set "[A%%n]=%%v"
  294.    )
  295.   ) Else (%= Argument is input request =%
  296.    Set "input="
  297.    Set "MaxIn=![A%%n]:#=!"
  298.    If defined MaxIn Set "MaxIn=!MaxIn: =!"
  299.    If defined MaxIn Echo(!MaxIn!| %SystemRoot%\System32\findstr.exe /R "[^1234567890]" > nul && (
  300.     Call:FlagError "Invalid Argument value for input request %%n: "!MaxIn!". Positive integer required" > Con
  301.     Goto:EndRun
  302.    )Else Set "MaxIn=2147483647"
  303.    For /l %%z in (0 1 99)Do if not defined input (
  304.     Set /P "input=Enter Input %%n (Integer LEQ !MaxIn!): " > Con
  305.     Set /a "input=!input!+0","1/input","1/(1/((input>>32)-1))","1/(MaxIn/Input)" 2> nul || (
  306.      Echo(Invalid input. > Con
  307.      Set "input="
  308.     )
  309.    )
  310.    Set "[A%%n]=!input!"
  311.    Cls
  312.    If not defined input set "input=1"
  313.    (Echo(Input %%n: !input!) >>"%~f0:Dev.log"
  314.    For /f "Delims=" %%G in ("!input!")Do Set "_=!_:$_%%n=%%G!"
  315.   )
  316.  )
  317.  
  318.  Set "Spacing="
  319.  For /l %%i in (1 1 1000)Do Set "Spacing=!Spacing! "
  320.  
  321. Rem catch use of /D switch without command list or other args
  322.  If not defined _ Goto:Syntax
  323.  
  324.  >"%~f0:Dev.log" (
  325.   Echo(============================================================================================================
  326.   Echo( Command Line    : !CL!
  327.  )
  328.  If defined devmode >>"%~f0:Dev.log" 2> nul (
  329.   For /f "Tokens=1,2* Delims==" %%G in ('Set [A')Do If NOT "%%G"=="[A0]" Echo(%%G : %%H
  330.  )
  331.  
  332.  Set ^"_=!_:"=!"
  333.  Set "_=!_:`(=//O!"
  334.  Set "_=!_:`)=//C!"
  335.  Set "_=!_:`:=//S!"
  336.  Set "_=!_: {={!"
  337.  Set "_=!_: (=(!"
  338.  Set "_=!_: )=)!"
  339.  Set "_=!_:} =}!"
  340.  
  341. Set "Array?="
  342. Rem test {ArrayList;Index} usage; assign Stack array and Index if valid syntax and trailing command list.
  343. Rem flag Syntax Errors. Outer if condition prevents parsing error for unqouted commandlines beginning with "("
  344.  
  345.  If Not "!_:;=!"=="!_!" If Not "!_:}=!"=="!_!" If Not "!_:~0,1!"=="{" If not "!_:~0,1!"=="`" (
  346.   Call:FlagError "Missing Opening curly brace '{' in Command Line: '!_!'"
  347.   Goto:EndRun
  348.  )
  349.  
  350.  If NOT "!_:~0,1!"=="(" (
  351.   If "!_:~0,1!"=="{" (
  352.    If "!_:}=!"=="!_!" (
  353.     Call:FlagError "Missing Closing curly brace '}' in Command Line"
  354.     Goto:EndRun
  355.    )
  356.    Set "Array?=%CL:}=}"&Rem ::%
  357.    If not "!_:;=!"=="!_!" (
  358.     If not "!_:}=!"=="!_!" (
  359.      For /f "tokens=1,2,3 delims={;}" %%G in ("!_!") Do (
  360.       Set "Stack=0"
  361.       For %%i in (%%G)Do (
  362.        Set /A "stack+=1,stack[!stack!]=%%i"
  363.       )
  364.       If not %%H GTR !Stack! (
  365.        If not %%H LSS 0 (
  366.         Set /A "Stack=%%H" 2> nul
  367.        )Else (
  368.         Call:FlagError "Stack outside array boundary OR missing array / index in {arraylist;index}"
  369.         Goto:EndRun
  370.        )
  371.       ) Else (
  372.        Call:FlagError "Stack outside array boundary OR missing array / index in {arraylist;index}"
  373.        Goto:EndRun
  374.       )
  375.       If "%%I"=="" (
  376.        Call:FlagError "Command list Required."
  377.        Goto:EndRun
  378.       )
  379.       Set "_=%%I"
  380.      )
  381.      Set /A v=Stack[!stack!]
  382.     )Else (
  383.      Call:FlagError "Closing '}' missing in arg string"
  384.      Goto:EndRun
  385.     )
  386.    )Else (
  387.     Call:FlagError "{ArrayList;index} sepererator ';' missing in arg string"
  388.     Goto:EndRun
  389.  )))
  390.  
  391. Set /A "Loop=0"
  392.  
  393. REM Parse loops in arg
  394.  
  395.  Set /A "O_P=C_P=S_C=B_T=E_A=0"
  396.  Set "null=%_:`=" & Set /A "B_T+=1" & Set "null=%"
  397.  Set "null=%_:(=" & Set /A "O_P+=1" & Set "null=%"
  398.  Set "null=%_:)=" & Set /A "C_P+=1" & Set "null=%"
  399.  Set "null=%_::=" & Set /A "S_C+=1" & Set "null=%"
  400.  Set "null=%_::)=" & Set /A "L_R+=1" & Set "null=%"
  401.  
  402.  If !L_R! GTR 0 (
  403.   Call:FlagError "Missing Command Token: Loop repeat Value absent in (Command:RepeatCount) Usage."
  404.   Goto:EndRun
  405.  )
  406.  
  407.  If !O_P! GTR !C_P! (
  408.   Call:FlagError "Missing Closing parentheses in Command Line. Opening:!O_P! Closing:!C_P!"
  409.   Goto:EndRun
  410.  )
  411.  If !C_P! GTR !O_P! (
  412.   Call:FlagError "Missing Opening parentheses in Command Line. Opening:!O_P! Closing:!C_P!"
  413.   Goto:EndRun
  414.  )
  415.  
  416.  If not "!O_P!!C_P!"=="00" (
  417.   2> nul Set /A "Seperators=((O_P + C_P) / S_C)"
  418.   If !Seperators!0 NEQ 20 (
  419.    Call:FlagError "Error - Invalid loop syntax, unbalanced ':' Seperator in Command Line. Loops:!O_P! Seperators:!S_C!. If a literal string" /N
  420.    Call:FlagError "... precedes the ':' Seperator, delimit literal string and seperator using a comma or whitespace. IE: (`this`,:3)" /N
  421.    Goto:EndRun
  422.   )
  423.  )Else (%= Command Contains no loops. Skip Loop parsing. =%
  424.   If !B_T! EQU 0 If !S_C! GTR 0 (
  425.    Call:FlagError "Invalid ':' Usage. Use with parentheses to demark loop: '(Commands:Integer)'"
  426.    Call:FlagError "Invalid ':' Usage. Use backticks to indicate string literal: `String:String`"
  427.    Goto:EndRun
  428.   )
  429.   Goto:SkipBuildReps
  430.  )
  431.  
  432. :BuildReps
  433.  
  434.  Set "Last_=!_!"
  435.  Set "Lead=" & Set "Trail=" & Set "Replace="
  436.  If not "!_:(=!"=="!_!" Set "Lead=!_:*(=!"
  437.  For /L %%i in (0 1 10)Do If defined Lead Set "Lead=!Lead:*(=!"
  438.  
  439.  If defined Lead Set Lead | %SystemRoot%\System32\findstr.exe /lic:")" > nul || (
  440.   Call:FlagError "Malformed Loop Syntax - Missing ')' in Command Line"
  441.   Goto:EndRun
  442.  )
  443.  If defined Lead Set Lead | %SystemRoot%\System32\findstr.exe /lic:":" > nul || (
  444.   Call:FlagError "Malformed Loop Syntax - Missing ':' in Command Line"
  445.   Goto:EndRun
  446.  )
  447.  If Defined Lead Set "Trail=%Lead:)="&Rem::%
  448.  If Defined Lead Set "Lead=%Lead:)="&Rem::%
  449.  If defined Lead For /f "tokens=1,2 Delims=:" %%G in ("!Lead!")Do (
  450.   Set "Lead=%%G"
  451.   Set "Trail=%%H"
  452.  )
  453.  
  454.  Set "Replace="
  455.  If defined Trail Echo(!Trail!|%SystemRoot%\System32\findstr.exe /XR "[123456789][0123456789]*" > nul && (
  456.   For /l %%i in (1 1 !Trail!)Do (
  457.    Set "Replace=!Replace!!Lead!"
  458.    If not "!Replace:~3750,1!"=="" (
  459.     Call:FlagError "Parsed Command line exceeds supported length. 3750 character limit applies"
  460.     Echo( Parse State: "!_!" >>"%~f0:Dev.log"
  461.     Echo( Attempted Parse Action: "(!Lead!:!Trail!)=!Replace!" >>"%~f0:Dev.log"
  462.     Goto:EndRun
  463.    )
  464.   )
  465.  ) || (
  466.   Call:FlagError "Invalid Command token For Loop RepeatCount ':!Trail!' - Positive Integer Required."
  467.   Goto:EndRun
  468.  )
  469.  
  470.  If Defined Replace Set "_=!_:(%Lead%:%Trail%)=%Replace%!"
  471.  
  472.  If /I not "!Last_!"=="!_!" (
  473.   Set /A Loop += 1
  474.   If defined devmode (
  475.    Echo(Loop parse [!Loop!] : !REG3XP0!>"(!Lead!:!Trail!)" >>"%~f0:Dev.Log"
  476.    Echo(Parse state : "!_!" >>"%~f0:Dev.Log"
  477.   )
  478.   Goto:BuildReps
  479.  )
  480.  
  481. :SkipBuildReps
  482.  
  483. REM updated parsing method to permit use of string literals by using '`' to flag start and end of a literal string
  484.  
  485.  Set /A "1 / (B_T %% 2)" 2> nul && (
  486.   Call:FlagError "Unpaired Literal delimiters '`' in Command Line. Escape Literal '(' and ')': '`(' or '`)'"
  487.   Goto:EndRun
  488.  )
  489.  
  490.  Set "Parse="
  491.  Set "Isliteral="
  492.  Set "DQstate=0"
  493.   For /l %%i in (0 1 8000)Do If not "!_:~%%i,1!"=="" (
  494.    Set "Char=!_:~%%i,1!"
  495.    If /I "!_:~%%i,1!"=="`" (
  496.     Set "IsLiteral=true"
  497.     2> nul Set /a 1/DQstate && (
  498.      Set ^"Parse=!Parse!""
  499.      Set /a "DQstate=0"
  500.     ) || (
  501.      Set ^"Parse=!Parse! ""
  502.      Set /a "DQstate=1"
  503.     )
  504.    )Else (
  505.     If "!DQstate!"=="0" (%= Token is Command =%
  506.      Set "Char=!Char:$=# a !"
  507.      Set "Char=!Char:_=i a !"
  508.      Set "Parse=!Parse! !Char!"
  509.     )Else (%= Token forms part of a Literal String =%
  510.      If not "!Char!"=="*" (
  511.       Set "Parse=!Parse!!Char!"
  512.      )Else Set "Parse=!Parse!//A"
  513.     )
  514.    )
  515.   )
  516.  
  517. Set "_=!Parse!"
  518.  
  519. REM Golfing feature: Any program comprised of a single valid command is a quine - Excludes $ and _ .
  520.  
  521.  If /I not "!_: =!"=="!_!" (
  522.   If /I "!_:~2,1!"=="" (
  523.    <nul Set/p "=.%\b%!_: =!"
  524.    Goto:EndRun
  525.   )
  526.  )
  527.  
  528.  Set "args=!_!"
  529.  
  530.  If not defined Stack set Stack=0
  531.  If not defined v Set v=0
  532.  
  533. REM define Arithmetic command Macros. Approximations used due to Integer Limitation.
  534. REM  r = Square root ; i = increment ; d = decrement ; s = square ; z = zero ;
  535. REM  h = half ; t = double ; . = Mulitply by 10 ; p = Mulitply by Pi
  536.  
  537.  set r="v=( M=(v), x=M/(11*1024)+40, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x+=(M-x*x)>>31 )"
  538.  Set i=v+=1&Set d=v-=1&Set s=v*=v&Set z=v=0&Set h=v/=2&Set t=v*=2&Set .=v*=10
  539.  Set p="v=(v*3142)/1000"
  540.  
  541.  >>"%~f0:Dev.log" (
  542.   Echo(Parsed  CL    : !Array?!!args!
  543.   Echo(Parsed  Loops : !Loop!
  544.  )
  545.  
  546.  Set "tops=0"
  547.  2>nul (%!! command;Else Output =%
  548.   If not Defined CommandError For %%i in (!args!)Do If not "%%~i"=="" (
  549.    Set "outv= Output: ``"
  550.    Set "CMDTKN=%%~i"
  551.    Set "CMDTKN=!CMDTKN://A=*!"
  552.    If not defined stack Set "stack=0"
  553.    For %%v in (!Stack!)Do If "!stack[%%v]!"=="" Set /A stack[!stack!]=v+0
  554.    Set /A tops+=1
  555.    If /i "%%~i"=="A" (
  556.     If defined Uni[!v!] (
  557.      For /f delims^= %%v in ("!v!")Do (
  558.       <nul Set /p ^"=.%\b%!Uni[%%v]!"
  559.       Set ^"outv= Output: '!Uni[%%v]!'"
  560.      )
  561.     )
  562.    )Else If /i "%%~i"=="N" ( Echo(%= Newline =%
  563.    )Else If /i "%%~i"=="W" ( For %%v in (!v!)Do <nul set /p "=.%\b%!Spacing:~-%%v!"
  564.    )Else If /i "%%~i"=="5" ( If defined win10 <nul set /p"=%\E%[5m"     %= Set Cursor Blinking; No Equivelant non VT command =%
  565.    )Else If /i "%%~i"=="2" ( If defined win10 <nul set /p"=%\E%[B"      %!!%
  566.    )Else If /i "%%~i"=="4" ( If NOT defined Win10 <nul set /p"=%\b%"    %= Cursor Left - Destructive =%
  567.                              If defined win10 <nul set /p"=%\E%[D"      %= VT Cursor Left - Non Destructive =%
  568.    )Else If /i "%%~i"=="6" ( If NOT defined Win10 <nul Set /p"=.%\b% "  %= Cursor Right - Destructive =%
  569.                              If defined win10 <nul set /p"=%\E%[C"      %= VT Cursor Right - Non Destructive =%
  570.    )Else If /i "%%~i"=="8" ( If defined win10 <nul set /p"=%\E%[A"      %!!%
  571.    )Else If /i "%%~i"=="1" ( If defined win10 <nul set /p"=%\E%8"       %= VT Restore cursor position from memory =%
  572.    )Else If /i "%%~i"=="7" ( If defined win10 <nul set /p"=%\E%7"       %= VT Save Cursor position in memory =%
  573.    )Else If /i "%%~i"=="C" ( If defined win10 <nul set /p"=%\E%[1;1H"   %= VT Move Cursor Home =%
  574.    )Else If /i "%%~i"=="B" ( If defined win10 <nul set /p "=%\E%[48;5;!v!m"  %= VT Set background color to current pointer value =%
  575.    )Else If /i "%%~i"=="F" ( If defined win10 <nul set /p "=%\E%[38;5;!v!m"  %= VT Set foreground color to current pointer value =%
  576.    )Else If /i "%%~i"=="~" ( If NOT defined win10 Color 07              %= Color Reset - Whole of screen =%
  577.                              If defined win10 <nul set /p "=%\E%[0m"    %= Color Reset - restores default color for any subsequent output =%
  578.    )Else If /i "%%~i"=="J" ( If NOT defined win10 CLS                   %= Whole screen Clear =%
  579.                              If defined win10 <nul set /p "=%\E%[0J"    %= Clear screen from cursor location =%
  580.    )Else If /i "%%~i"=="+" ( Set /A "stack+=1"                          %= PUSH =%
  581.    )Else If /i "%%~i"=="-" (                                            %= POP - Prevents Negative stack indexes. =%
  582.     If NOT !stack!==0 (
  583.      Set /A stack-=1
  584.     )Else (
  585.      Set "outv= Error : 'OOB'"
  586.     )
  587.    )Else If /i "%%~i"=="@" ( Set /a "stack[!stack!]=v"                  %= Store pointers [rVal] value in the current stack =%
  588.    )Else If /i "%%~i"=="#" ( Set /a "v=stack[!stack!]"                  %= Assign value stored in the current stack to the pointer =%
  589.    )Else If /i "%%~i"=="]" ( Set /a "v+=stack[!stack!]+0"               %= Increment the pointer with the value stored in the current stack =%
  590.    )Else If /i "%%~i"=="[" ( Set /a "v-=stack[!stack!]+0"               %= Decrement the pointer with the value stored in the current stack =%
  591.    )Else If /i "%%~i"=="Q" (                                            %= Quit processing if the value stored in the current stack equals the Pointers current value =%
  592.     For %%v in (!Stack!)Do If !v!==!Stack[%%v]! Goto:EndRun
  593.    )Else If not "!CMDTKN::=!"=="!CMDTKN!" (                             %!!%
  594.            Set "CMDTKN=!CMDTKN://S=:!"
  595.            Set "CMDTKN=!CMDTKN://O=(!"
  596.            Set "CMDTKN=!CMDTKN://C=)!"
  597.            <nul Set /p"=.%\b%!CMDTKN!"
  598.            If defined DevMode (
  599.             Set "outv= Output: '!CMDTKN!'"
  600.            )
  601.           )Else (
  602.            Set/A!%%~i! 2>nul|| (                                         %= Attempt to perform Arithmetic command using command macros. =%
  603.             If /I "%%~i"=="o" (                                          %= If fail; check if command equ output =%
  604.              <nul Set /p"=!v!"
  605.             )Else If "!CMDTKN:~0,1!"=="" (                               %= Output current pointer value if command token empty =%
  606.              <nul Set /p"=!v!"
  607.             )Else (                                                      %= Output Literal strings containg Exclamation marks =%
  608.              Set "CMDTKN=!CMDTKN://S=:!"
  609.              Set "CMDTKN=!CMDTKN://O=(!"
  610.              Set "CMDTKN=!CMDTKN://C=)!"
  611.              CMD /C Exit 33
  612.              CALL Set "CMDTKN=!CMDTKN:XCLM=%%=EXITCODEASCII%%!"
  613.              <nul Set /p"=.%\b%!CMDTKN!"
  614.              If defined DevMode (
  615.               Set "outv= Output: '!CMDTKN!'"
  616.              )
  617.             )
  618.           )
  619.    )
  620.    If defined devmode (                                                   %= Enact additional Command Logging =%
  621.     Set "Stackarray="& If not Defined outv Set "outv=| Output: ``"
  622.     For %%v in (!stack!)Do ( If "!stack[%%v]!"=="" Set /A "stack[!stack!]=v+0"
  623.      For /f "delims=" %%G in ('Set Stack[')Do For /f "Tokens=2,3 delims=[]=" %%H in ("%%G")Do Set "stackarray=!stackarray!,%%I"
  624.      If /I "%%~i"=="O" (
  625.       Set "outv= Output: '!v!'"
  626.      )Else If /I "%%~i"=="N" (
  627.       Set "outv= Output: '\n'"
  628.      )
  629.      >>"%~f0:Dev.log" Echo({Cmd: %%~i ; !tops! }    ^| Val:!v!  ^| Stack %%v: !Stack[%%v]!  ^|!Outv!    ^| Stacks: !stackarray:~1!
  630.  ))))
  631.  
  632. :EndRun
  633.  If not Defined CommandError (%= Pause if program completed succesfully =%
  634.   Title Press any key to continue
  635.   If not defined ExampleMode Pause > nul
  636.  )
  637.  (Title )
  638.  
  639.  Echo(
  640.  Endlocal & Endlocal & Set "DevMode=%DevMode%" & Set "rVal=%v%"
  641.  
  642.  If defined DevMode (
  643.   For /f "Delims=" %%G in ('more ^< "%~f0:Dev.log"')Do Echo(%%G
  644.  )
  645.  
  646. Exit /b 0
  647.  
  648. :Syntax
  649. for /F %%a in ('Echo(prompt $E^| cmd')Do Set \E=%%a
  650.  
  651. SETLOCAL DISABLEdelayedexpansion
  652.   Echo =============================================================================================================
  653.   Echo                                                                                          BatchStax by T3RRY
  654.   Echo( %~n0 Syntax
  655.   Echo( %~n0    [/D] [{ArrayList;Index}^|ArrayList;Index‡] [(commands:RepeatCount)][commands] [?IntArg/s] [?#MaxInt]
  656.   Echo( Commands:   $ A B C D F H I J N O P Q R S T U Z @ # [ ] + - 1 2 4 6 7 8 ~ . `literal string`
  657.   Echo(
  658.   Echo  * [type] denotes an optional command, loop switch or arguments - note: If {ArrayList;int} is used, it must preceed the command list.
  659.   Echo  * ArrayList denotes a comma seperated list of initial stack values, followed by a ';' seperated Index[integer]
  660.   Echo    to declare the Stack location in which to commence. See examples below.
  661.   Echo  * (Commands:RepeatCount) ; where RepeatCount is an Integer: Repeat command group enclosed within parentheses
  662.   Echo    Integer times.
  663.   Echo    ** NOTE: Nested loops are now supported.
  664.   Echo(            Stack position and rVal are not implicity modified when a loop is enacted; Commands must
  665.   Echo             be used to Ensure stack location and rVal have the values necessary to achieve expected output.
  666.   Echo             - note example 2, and how the final 2 commands are used to prepare for the next loop iteration.
  667.   Echo(
  668.   Echo  /D               : switch ; Enables log output
  669.   Echo  `Literal String` : text between backticks denotes literal text to output.
  670.   Echo                     - Valid single character Commands overide flagging of literal state.
  671.   Echo                     - Literal use of  '(', ':' and ')' require escaping using '`'
  672.   Echo(                      Examples: ``(` or ``(and`)`
  673.   Echo(                      - Failure to escape Parentheses for literal output may result in Unbalanced '`', ':', '(' or ')' Errors
  674.   Echo( ?IntArg/s        : One or more Integer or Integer Arithmetic expressions used as input for the preceeding command set, delimited by a ? prefix.
  675.   Echo(                    Args, if used, must terminate the command line (/D switch excepted).
  676.   Echo(                    The Integer argument or the result of the Arithmetic expression must be positive a positive Integer.
  677.   Echo(                    Args can be referenced in the command line using $_index. $_1 To reference the first arg, $_2 the second and so on.
  678.   Echo(                    Argument order is left to right. ?IntArgs may refer to previous input arguments Using [Aindex] - See below example.
  679.   Echo( [?#MaxInt]       : Request user input, constrained to a positive integer below Integer value provided: IE ?#50 accepts any integer from 1 to 50.
  680.   Echo(                    See example 7.
  681.   Echo(
  682.   Echo( [?u] or [¿]      : Similar to ?#MaxInt, however Maximum value is capped at 239, limiting input to the range of unicode/ascii character indices.
  683.  REM Additional example: takes 5 inputs, Prints a diamond with an asterisk at its heart. First four inputs - '¿' define the unicode/ascii
  684.  REM character to be used for each side, final input determines the length of each side - ?#Max.
  685.  REM   ¡1,¡2,¡3,¡4‡6(2:¡5)(8a:¡5)»(2a:¡5)»(2ª:¡5)7»(8ª:¡5)(6:¡5)4`*`1~¿¿¿¿?#25
  686.   Echo(
  687.   Echo  Arithmetic commands:
  688.   Echo  'I' + 1           'D' - 1
  689.   Echo  'T' * 2           'H' / 2
  690.   Echo  'P' * Pi          '.' * 10
  691.   Echo  'S' Square        'R' sqRoot
  692.   Echo  'Z' rVal = 0
  693.   Echo  * '[' and ']' operations are described in Stack based commands below.
  694.   Echo(
  695.   Echo  Virtual Terminal commands:
  696.   Echo  'J' Clear the screen from the current cursor position
  697.   Echo      ** If Virtual terminal unsupported, Clears the entire screen
  698.   Echo  'C' Move the Cursor to screen home.
  699.   Echo  'B' Backgound color = 48;5;rVal
  700.   Echo  'F' Foregound color = 38;5;rVal
  701.   Echo  '~' Reset Background and Foregound color to default.
  702.   Echo  '7' Save cursor position
  703.   Echo  '1' Restore cursor from saved position
  704.   Echo  '5' Set cursor blinking
  705.   Echo                  '8' Cursor Up
  706.   Echo  Cursor Left '4'     '6' Cursor Right
  707.   Echo                  '2' Cursor Down
  708.   Echo(
  709.   Echo  Output commands:
  710.   Echo  'O' Output rVal as integer
  711.   Echo  'A' Output ASCII or Unicode character for decimal value of rVal if within range: 1-239
  712.   Echo      - See: https://www.asciitable.com/
  713.   Echo  '$' Abbreviation of '#A'
  714.   Echo  'N' Output Newline
  715.   Echo  'W' Output rVal Spaces at the current cursor position.
  716.   Echo(
  717.   Echo  Stack based commands:
  718.   Echo  A note regarding Stacks:
  719.   Echo      - 'Stacks' in this script are a group of associated variables
  720.   Echo         that may be used as memory to store or retrieve values. Changing stack index using '+'
  721.   Echo         or '-' changes the variable being used as the storage / retrieval 'location'.
  722.   Echo      - Stacks are assigned the current rVal on creation, or the array values when {ArrayList:Index}
  723.   Echo        is used to predefine stacks.
  724.   Echo  'Q' Test if rVal is EQU current stack Value. Terminates if true
  725.   Echo  '+' Push ; increment stack counter
  726.   Echo  '-' Pop  ; decrement stack counter
  727.   Echo  '@' Save current rVal to current stack index.
  728.   Echo  '#' Assign current stack value to rVal [retrieve]
  729.   Echo  ']' Add value stored in current stack to rVal
  730.   Echo      * if last operation was '@' or '+' creating a new stack, this is equivalent to doubling rVal
  731.   Echo  '[' Subtract value stored in current stack from rVal
  732.   Echo      * if last operation was '@' or '+' creating a new stack, this is equivalent to setting rVal to 0
  733.   Echo(
  734.   Echo  Example 1 - Print: "Hello World!"
  735.   Echo=   %~f0 `Hello World!`
  736.   Echo(
  737.   Echo  Example 2 - Print: "Hello World!" Three times with trailing newline
  738.   Echo=   %~f0 (`Hello World!`n:3)
  739.   Echo(
  740.   Echo  Example 3 - Print "Hello World!" diagonally 0,0 to 11,11
  741.   Echo=   %~f0 ip@p+pd+]]-[a+]--]d2a+]dd2a2a-]][2a++[[[ï2a]]i2a]ddd2a--]2a[[2a+[i2arpï2a
  742.   Echo(
  743.   Echo  Example 4 - Print "COCA COLA!"
  744.   Echo=   %~f0 {33,65,67,79,32,76;2} $+$-$-$+++$--$+$++$----$-$
  745.   Echo(
  746.   Echo  Example 5 - Print: "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
  747.   Echo=   %~f0 62,32‡ï▀+]a([-▀+]a:25)
  748.   Echo(
  749.   Echo  Nested loops are supported, to an expanded command length of 3750 characters. Examples:
  750.   Echo  Example 6 - nested loop - Print a stepped pyramid, alternating colors.
  751.   Echo=   %~f0 124,45‡(6:21)(2»f«a4'42ƒ4:7)n8(8a8»ƒa«f:7)»a«(»ƒa«f2a2:7)~
  752.   Echo(
  753.   Echo( Example 7 - (same as example 6, except uses Argument input to vary Loop repetitions and change output size):
  754.   Echo=   %~n0 124,45‡(6:¡2)(2»f«a4'42ƒ4:¡1)n8(8a8»ƒa«f:¡1)»a«(»ƒa«f2a2:¡1)~?#30?[A1]*3
  755.   Echo(
  756.   Echo  Example 8 - nested loop - Draw a box, emit newline, repeat twice
  757.   Echo=   %~f0 61,124‡((a:5)»(24a:4)«4a(ª:5)»(84a:3)(n:5)«:2)
  758.   Echo(
  759.   Echo  Example 9 - nested loop - Print all ASCII characters in blue from 32-123 as a column 5 characters wide
  760.   Echo                            change color to pink; move cursor to screen home and print in another
  761.   Echo                            column in reverse order. Reset forground color to white at end of commandline.
  762.   Echo=   %~f0 32‡f((▄:5)n:19)C(6:6)f((da:5)n(6:6):19)~
  763.   Echo(
  764.   Echo  Example 10 - nested loop - Draw a blue Ascii art Comet:
  765.   Echo=   %~f0 32,33,42‡-((»f«ai@:2)2:48)++4$86a22a4ª8a6a~
  766.   Echo(
  767.   Echo  Example 11 - command "5" set cursor graphical mode to blinking. command "~" restores cursor graphical defaults
  768.   Echo=   %~f0 33 176‡((«5ƒ~2»ƒ8:5)nn:5)~
  769.   Echo(
  770.   Echo  Example 12 - Command logging: [deliberately malformed command - unbalanced parentheses]
  771.   Echo=   %~f0 /D ((▀:4)o:3)((ad:3)o):2)
  772.   Echo(
  773.   Echo =============================================================================================================
  774. ENDLOCAL
  775.   Timeout /t 1 /NoBreak > nul
  776.   Pause
  777.   Cls
  778.   For /l %%i in (0 1 5)Do if "!!"=="" Endlocal
  779.   Setlocal DisableDelayedExpansion
  780.   Set "ExampleCount=0"
  781.   Choice /N /C:YN /M "View example outputs Y/N?"
  782.   If %Errorlevel% EQU 1 (
  783.    Set "exampleMode=1"
  784.    For /f "tokens=2 Delims==" %%G in ('%SystemRoot%\System32\Findstr.exe /blic:"  Echo=" "%~f0"')Do (
  785.     Set /A "ExampleCount+=1"
  786.     Setlocal DisableDelayedExpansion
  787.     Set "Example=%%G"
  788. REM    CMD /V:ON /C "Title Example: !ExampleCount! = !Example:*%%~f0=!"
  789.    Rem Secondary call is used to expand literal %~f0 to this files filepath
  790.     2> nul Set /A "1/(ExampleCount-12)" || (
  791.      Cls
  792.      Echo(The next example Shows an example of error output When invalid syntax is used.
  793.      Pause 
  794.     )
  795.     Call call %%G
  796.     Setlocal EnableDelayedExpansion
  797.     Echo(%\E%7%\E%[1;1H%\E%[1TExample: !ExampleCount! = !Example:*%%~f0=%~nx0!%\E%8
  798.     Endlocal
  799.     Choice /C:nq /M "[N]ext [Q]uit"
  800.     If errorlevel 2 (Endlocal & Endlocal & Exit /b 1)
  801.     (Call )
  802.     Endlocal
  803.    )
  804.   )
  805.   Endlocal
  806.   Exit /b 0
  807.  
  808. ====================================================================================================================
  809. :FlagError <ErrorMessage>
  810.  
  811.  Set "ErrorMessage=%~1"
  812.  If defined Devmode (
  813.   Set "ErrorMessage= ** Error: !ErrorMessage:)=^)!"
  814.  ) Else Set "ErrorMessage= **   Error: !ErrorMessage!"
  815.  If not "%~2"=="" Set "ErrorMessage=!ErrorMessage:Error: =!"
  816.  If defined Devmode (
  817.   (
  818.   If "%~2"=="" Echo(============================================================================================================
  819.    (Echo( !ErrorMessage:^^=!)
  820.   If /I Not "%~2"=="/N" Echo(============================================================================================================
  821.   ) >> "%~f0:Dev.log"
  822.  ) Else (
  823.   If "%~2"=="" Echo(============================================================================================================
  824.   If "%~2"=="" Echo( Command Line: !CL!
  825.   If "%~2"=="" Echo(============================================================================================================
  826.    (Echo( !ErrorMessage:^^=!)
  827.   If /I Not "%~2"=="/N" Echo(============================================================================================================
  828.    ENDLOCAL
  829.   )
  830.  )
  831.  Set "CommandError=true"
  832. Exit /B
  833.  
  834.  
  835. :# The below line Marks the end of a Powershell comment Block; And the End of the Batch Script. Do not Modify.
  836. : end batch / begin powershell #>
  837. <#
  838.  Test if input Argument -eq ToggleFs
  839.  If true uses sendKeys to force fullscreen.
  840. #>
  841.  
  842. $InitW = $Host.UI.RawUI.WindowSize.Width
  843. $InitH = $Host.UI.RawUI.WindowSize.Height
  844.  
  845. $Mode -eq 'ToggleFS' >$null
  846.  
  847. If ($Mode -eq "ToggleFS") {
  848.     Add-Type -AssemblyName System.Windows.Forms
  849.     [System.Windows.Forms.SendKeys]::SendWait("{F11}")
  850.  
  851.     $CurrentW = $Host.UI.RawUI.WindowSize.Width
  852.     $CurrentH = $Host.UI.RawUI.WindowSize.Height
  853.  
  854.     If ($InitW -ge $CurrentW) {
  855.         If ($InitH -ge $CurrentH) {
  856.             [System.Windows.Forms.SendKeys]::SendWait("{F11}")
  857.         }
  858.     }
  859.  
  860. }
  861.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement