T3RRYT3RR0R

Random pattern maker - ASCII Art

Dec 15th, 2021 (edited)
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 25.74 KB | None | 0 0
  1. :$: Fun with random strings by T3RRY.
  2. @REM this script is a a fusion of my 'mirror' string mirroring and $rStr random string generating macros
  3. @Rem Example outputs can be seen here: https://pastebin.com/807EwzCs
  4.  
  5. @Echo off
  6. rem Powershell.exe -noprofile -nologo -command "Remove-item -path '%~f0' -Stream '*'"
  7. rem Goto:Eof
  8.  
  9.  Mode 1000
  10.  
  11. :@================================================================================================================
  12. :@ Filename [<Patterns{1}> <Lines{15}> <SubLength{8}> <HorizontalRepeats{8}> <VerticalRepeats{1}>] [NoFlip{false}]
  13. :@  NOTE: {Int} denotes the default. Only Integer strings will be accepted for Args 1-5. Any 6th Arg disables flip
  14. :@ @
  15. :@  Arg order mandatory
  16. :@  Args 1-5 will only accept positive integers. Use of Args is optional, however if used:
  17. :@  Args will be assigned in Expected order. Missing or invalid args, including negative
  18. :@  or 0 integers, will be replaced with default values.
  19. :@  Arg 6 is optional, requires Args 1-5 to be used.
  20. :@ @
  21. :@  FileName /? : This help.
  22. :@  FileName /? Mirror : Mirror macro help output
  23. :@  FileName /? Random : $rStr macro help output
  24. :@  FileName /? String : $rStr macro help output
  25. :@   - Note:
  26. :@     Arguments to this script have limited interaction with macros.
  27. :@ @
  28. :@::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  29. :@ @
  30. :@ Filename <filename.ext>
  31. :@  copy last pattern to Filename_filename.ext
  32. :@ @
  33. :@ Filename /s
  34. :@  Skip new pattern prompt, shows last pattern
  35. :@================================================================================================================
  36.  
  37.  2> nul (
  38.   Set /A "Patterns=%~1/1","1/Patterns"   || Set /A "Patterns=1"
  39.   Set /A "_Lines=%~2/1","1/_Lines"       || Set /A "_Lines=15"
  40.   Set /A "SubLength=%~3/1","1/Sublength" || Set /A "SubLength=8"
  41.   Set /A "HRepeats=%~4","1/HRepeats"     || Set /A "HRepeats=8"
  42.   Set /A "VRepeats=%~5","1/VRepeats"     || Set /A "VRepeats=1"
  43.   Set /A "1/(Patterns>>9)"  && Set /A "Patterns=1"
  44.   Set /A "1/(_Lines>>9)"    && Set /A "_Lines=15"
  45.   Set /A "1/(SubLength>>9)" && Set /A "SubLength=8"
  46.   Set /A "1/(HRepeats>>9)"  && "HRepeats=8"
  47.   Set /A "1/(VRepeats>>9)"  && "VRepeats=1"
  48.  )
  49.  
  50. Rem dual purpose variable - header length + Arg to override Mirror macro max stringlen
  51.  Set /A "hlen=(HRepeats*(SubLength*2))-Hrepeats"
  52.  
  53.  If "%~6"=="" (
  54.   Set "flip= /F"
  55.  )Else Set "flip="
  56.  
  57.  Set "Args=%*"
  58.  
  59.  If defined Args Set Args | %SystemRoot%\System32\Findstr.exe /EL "\/? -? help" > nul && (
  60.   For /f "tokens=2* Delims=@" %%G in ('%SystemRoot%\System32\Findstr.exe /bl ":@" "%~f0"')Do (
  61.    Set "Help=%%G"
  62.    Cmd /Von /C "Echo(!Help: FileName= %~n0!"
  63.   )
  64.   Pause
  65.   Exit /b 0
  66.  )
  67.  
  68.  Cls & Call:DefMacros %hLen%
  69.  If errorlevel 1 (
  70.   Exit /b
  71.  )
  72.  
  73.  Setlocal EnableDelayedExpansion
  74.  
  75.  Set "Divline="
  76.  Set "Header="
  77.  For /l %%i in (0 1 %Sublength%)Do (
  78.   set "Divline=!Divline!="
  79.  )
  80.  For /l %%n in (1 1 %hlen%)Do Set "Header=!Header!="
  81.  
  82.  cls
  83.  
  84. Rem Redirection and Errorlevel management via Call critical in respectively controlling the:
  85. rem output and conditional flow of the below code block
  86.  
  87.  2> nul (%= Supress STDerr if ADS not populated =%
  88.   More < "%~f0:Patterns.dat" > nul %!!% && (%= If ADS populated then =%
  89.    If not "%~x1"=="" (
  90.     Call :Skip 1>"%~dp0%~n0_%~1"
  91.     Exit /b 0
  92.    )
  93.    If /I "%~1"=="/S" Goto:Skip
  94.    If "%~2"=="" (
  95.     Choice /M "New Pattern?"
  96.    )Else ((Call))
  97.    %= CTRL+C is pressed =% If !errorlevel!==0 Goto:Eof
  98.    %=   User selects No =% If !errorlevel!==2 Goto:Skip
  99.    Cls
  100.    %= Force +ve errorlevel =% (Call)
  101.   )%= Else on +ve Errorlevel =% || %= Populate ADS with STDout produced in For loop. =% 1>"%~f0:Patterns.dat" (
  102.    Title Generating Strings...
  103.    Echo(!Header!
  104.    1> Con Echo(!Divline!
  105.    For /l %%n in (1 1 %Patterns%)Do (
  106.     Set "Str[%%n]="
  107.     For /l %%i in (1 1 %_Lines%)Do (
  108.      %$rStr% /l %SubLength% /P "  .  x  {AS} '   +  ~" /S 18 /V $rStr[RV]
  109.      If defined Str[%%n] (
  110.       Set Str[%%n]=!Str[%%n]! "!$rStr[RV]![!HRepeats!]",
  111.       1> Con Echo(!$rStr[RV]!^|%= Redirect STDout to console. =%
  112.      ) Else (
  113.       Set Str[%%n]="!$rStr[RV]![!HRepeats!]",
  114.       1> Con Echo(!$rStr[RV]!^|
  115.      )
  116.     )
  117.     1> Con Echo(!Divline!
  118.     Title Combining Pattern...
  119.     %Mirror:#=!VRepeats!% !Str[%%n]:~0,-1!!flip!
  120.     Echo(!Header!
  121.     (Title )
  122.   ))
  123.   1> Con Pause
  124.  )
  125.  
  126. :Skip
  127. cls
  128.  For /f Delims^= %%G in ('more ^< "%~f0:Patterns.dat"') Do Echo(%%G
  129.  
  130. Endlocal
  131. @Goto:Eof
  132.  
  133. ::====================== | Mirror MACRO Definition. Author - T3RRY | =====================
  134. :DefMacros
  135. ::| DefMirror USAGE:
  136. ::| *** Version changes 11/11/2021:
  137. ::|     /F 'Flip' switch added. Mirrors pattern vertically. ! Limited to Small patterns.
  138. ::| *** Version changes 9/11/2021:
  139. ::|     [Int] and {Int} partial repetition subargs may now be interchangeably positioned at string left or right.
  140. ::|     Doublequote is now escaped with itself: "" to print " - Each paired " is substituted to `DQ` before string processing.
  141. ::|     Multiple linefeeds may now be effected using %Mirror% "{Int}"
  142. ::|     Usage examples and help info updated to reflect changes.
  143. ::|
  144. ::| Call :DefMirror ["/?"]|[Int]
  145. ::| "/?" This help info.
  146. ::| Int - Overrides default max string length [ Default = 50 characters per "string" ]
  147. ::|
  148. ::| Mirror Macro Usage:
  149. ::| %Mirror% "string" [/F]
  150. ::| %Mirror% "string" "otherstring" [/F]
  151. ::| %Mirror% "string","otherstring" [/F]
  152. ::| %Mirror% "string", "otherstring" [/F]
  153. ::| %Mirror% "string" , "otherstring" [/F]
  154. ::|
  155. ::| Whole Pattern repetition:
  156. ::| Repeat the whole Pattern Int number of times:
  157. ::| %Mirror:#=Int% "String","OtherString"
  158. ::|
  159. ::| Partial Pattern repetition:
  160. ::| %Mirror% "string[Int]" or "[Int]string" ; Where Int is a number [1-99]: Repeat mirrored string Int times Horizontally.
  161. ::| %Mirror% "string{Int}" or "{Int}string ; Where Int is a number [1-99]: Repeat mirrored string Int times Vertically.
  162. ::| ** Repetition features may be combined: %Mirror:#=2% "{Int}string[Int]" or %Mirror:#=2% "[Int]string{Int}"
  163. ::| ** Strings beginning / ending with {Int} or [Int] ALWAYS trigger this behaviour If Int is GTR 0 LSS 100.
  164. ::|
  165. ::| Additional Info:
  166. ::| ** Delayed expansion must NOT be enabled prior to calling DefMacros
  167. ::| ** Delayed expansion is toggled on/off by %Mirror% macro and is NOT REQUIRED to be enabled prior to expansion the macro.
  168. ::| ** Mirror macro does not require echo state to be off, and expands in it's own local environment.
  169. ::|    - 'Reverse*CHAR' 'Flip*CHAR' '_Hash' and 'LF' variables are defined in the calling scripts environment.
  170. ::| ** Macro args MUST be doublequoted if multiple args are supplied, failure to doublequote will result in
  171. ::|    the string being treated as a single arg and may cause unexpected behaviour if the string contains poison characters.
  172. ::| ** A temporary file is used to facilitate handling of `*` character, which cannot be handled directly in a for loop.
  173. ::| ** Calling :DefMirror with a MaxLength Shorter than a supplied strings length will result in the macro hanging.
  174. ::| ** To print a newline using the macro, The string value must contain 2 or more whitespaces: "  "
  175. ::|    To print multiple newlines: "{Int}" ; Where Int is number GTR 0 LSS 100
  176. ::|
  177. ::| Supports all ASCII Characters, Observing the following usage information and ESCAPING Requirements:
  178. ::|  - ; Is reserved as a shading character - It will print on the left hand side of the string, and be replaced
  179. ::|      with a whitespace on the right.
  180. ::|  - @ is reserved for signalling the end of mirroring. Text following @ is printed between mirrored text.
  181. ::|      to use @ literally, escape it with itself: @@ [note: doing so will result in all text following @@ being mirrored.]
  182. ::|  - To print a doublequote, escape it with itself: "str""ing" will print: str"inggni"rts
  183. ::|  - ! must be triple escaped: ^^^!
  184. ::|    - /F Switch is incompatable with !, even when escaped.
  185. ::|    - Any string containing ^^^! will require literal carets to also be triple escaped:
  186. ::|      IE: "^^^^Hello, World^^^! " to print: "^Hello, World!  !dlroW ,olleH^"
  187. ::|  - % must be escaped: %%
  188. ::|
  189. ::========================================================================================
  190.  
  191.  @If "!!"=="" @(Echo(Delayed expansion not permitted prior to macro definition.& @Pause & @Exit/b 1)
  192.  @If defined Args (
  193.   @Set Args | %SystemRoot%\System32\Findstr.exe  /elic:"Mirror" > nul && @(
  194.    %SystemRoot%\System32\Findstr.exe  /blic:"::" "%~f0" | more
  195.    Exit /b 1
  196.   )
  197.   Set Args | %SystemRoot%\System32\Findstr.exe /eli "Random String" > nul && @(
  198.    %SystemRoot%\System32\Findstr.exe /blic:":#" "%~f0" | more
  199.    Exit /b 1
  200.   )
  201.  )
  202.  
  203.  @Set "_Hash=#"
  204. @(Set LF=^
  205.  
  206.  
  207. %= LF Linefeed variable Used in macro. Do not Modify. =%)
  208.  
  209. @(Set \n=^^^
  210.  
  211.  
  212. %= \n Newline variable for macro definition. Do not Modify =%)
  213.  
  214.  @For %%G in ("(=)" ")=(" "[=]" "]=[" "{=}" "}={" "/=\" "\=/")Do @Set "Replace%%~G"
  215.  @For %%G in ("M=W" "W=M" "6=9" "9=6" "v=^" "^=v" "`=." ".=`")Do @Set "Flip%%~G"
  216.  @Set "Flip'=,"
  217.  @Set "Flip,='"
  218.  
  219.  @Set "_EX=^!"
  220.  @Set "Replace>=<"
  221.  @Set "Replace<=>"
  222.  
  223.  @Setlocal
  224.  @Set "MaxLen=0"
  225.  @For %%G in (%*)Do @Set/A "MaxLen=%%~G" 2> nul || @Set "MaxLen=50"
  226.  @If %MaxLen% LEQ 0 @Set "MaxLen=50"
  227.  
  228.  @Endlocal & @Set Mirror=@For %%v in (1 2)Do @if %%v==2 (%\n%
  229.   @If Defined Mirror.Input (%\n%
  230.    @Set "[F]="%\n%
  231.    @If /I "!Mirror.Input:~-3!"==" /F" @(%\n%
  232.     @Set "Mirror.Input=!Mirror.Input:~0,-3!"%\n%
  233.     @Set "[F]=true"%\n%
  234.    )%\n%
  235.    @Set "#="%\n: Undefined in local environment to ensure no false positives below =%
  236.    @If not "!_Hash!"=="#" @(Set /A "1 / #" 2^> nul ^&^& (@Set /A "_Repeat=#") ^|^| @Set "_Repeat=1")Else @Set _Repeat=1%\n%
  237.    @For /l %%T in (1 1 !_Repeat!)Do @(%\n: Repeat entire pattern from args list. For loop input will repeated each input. =%
  238.     @Set "_F="%\n%
  239.     @Set "Mirror.Input=!Mirror.Input:*"="!"%\n: Strip leading characters that precede first doublequote =%
  240.     @Set "Mirror.Input=!Mirror.Input:""=`DQ`!"%\n: Enact temp Substitution of Escaped Doublequotes =%
  241.     @For %%G in ("!LF!")Do @(%\n: Delim args with a newline prior to outputting to file. =%
  242.      @Set "Mirror.Input=!Mirror.Input:" , "=%%G!"%\n%
  243.      @Set "Mirror.Input=!Mirror.Input:", "=%%G!"%\n%
  244.      @Set "Mirror.Input=!Mirror.Input:","=%%G!"%\n%
  245.      @Set "Mirror.Input=!Mirror.Input:" "=%%G!"%\n%
  246.     )%\n%
  247.     ^>"%~dpn0_In.~tmp" (Echo(!Mirror.Input!)%\n: Output prepared args to allow processing of all ASCII characters. =%
  248.     @For /f "usebackq Delims=" %%G in ("%~dpn0_In.~tmp")Do @(%\n: Read and process args line by line =%
  249.      @Set "_P="%\n: nul var used to Flag escaping of @ character =%
  250.      @Set "_S="%\n: nul Arg output var =%
  251.      @Set "_V=%%~G"%\n: Define Arg string =%
  252.      @Set/A"_Y=_X=1"%\n: Define default Horizontal and vertical Arg repeat counts =%
  253.      @Set ^"_V=!_V:"=!"%\n: Strip Doublequotes from Arg =%
  254.     @Rem %\n: Begin Assessment and flagging of [Int] X {Int} Y Partial repetition subargs =%
  255.      @Set /A 1 / !_V:~1,1! 2^> nul ^&^& @If "!_V:~0,1!!_V:~2,1!"=="{}" (%\n%
  256.       @Set "_Y=!_V:~1,1!"%\n%
  257.       @Set "_V=!_V:~3,%MaxLen%!"%\n%
  258.      )Else @If "!_V:~0,1!!_V:~2,1!"=="[]" (%\n%
  259.       @Set "_X=!_V:~-1,1!"%\n%
  260.       @Set "_V=!_V:~1,1!"%\n%
  261.      )%\n%
  262.      @Set /A 1 / !_V:~1,2! 2^> nul ^&^& @If "!_V:~0,1!!_V:~3,1!"=="{}" (%\n%
  263.       @Set "_Y=!_V:~1,2!"%\n%
  264.       @Set "_V=!_V:~4,%MaxLen%!"%\n%
  265.      )Else @If "!_V:~0,1!!_V:~3,1!"=="[]" (%\n%
  266.       @Set "_X=!_V:~1,2!"%\n%
  267.       @Set "_V=!_V:~4,%MaxLen%!"%\n%
  268.      )%\n%
  269.      @Set /A 1 / !_V:~-2,1! 2^> nul ^&^& @If "!_V:~-3,1!!_V:~-1!"=="[]" (%\n%
  270.       @Set "_X=!_V:~-2,1!"%\n%
  271.       @Set "_V=!_V:~0,-3!"%\n%
  272.      )Else @If "!_V:~-3,1!!_V:~-1!"=="{}" (%\n%
  273.       @Set "_Y=!_V:~-2,1!"%\n%
  274.       @Set "_V=!_V:~0,-3!"%\n%
  275.      )%\n%
  276.      @Set /A 1 / !_V:~-3,2! 2^> nul ^&^& @If "!_V:~-4,1!!_V:~-1!"=="[]" (%\n%
  277.       @Set "_X=!_V:~-3,2!"%\n%
  278.       @Set "_V=!_V:~0,-4!"%\n%
  279.      )Else @If "!_V:~-4,1!!_V:~-1!"=="{}" (%\n%
  280.       @Set "_Y=!_V:~-3,2!"%\n%
  281.       @Set "_V=!_V:~0,-4!"%\n%
  282.      )%\n: Next Line enacts escaping of @@ or splitting of Mirror / nonmirrored substrings =%
  283.      @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%
  284.      @If defined _V @Set ^"_V=!_V:`DQ`="!"%\n: enacts substitution to reinsert doublequotes =%
  285.      @Set "_I="%\n: nul string length variables =%
  286.      @Set "_Pi="%\n: Next line gets full string length =%
  287.      @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%
  288.      @If defined _P (%\n: Get offset length if @ used to split substring =%
  289.       @For /l %%i in (0 1 %MaxLen%)Do @If not defined _Pi @If "!_P:~%%i!"=="" @Set/A"_Pi=%%i"%\n%
  290.       @Set /A _O=_Pi-_O%\n%
  291.      )%\n%
  292.      @If Defined _V @For /l %%i in (0 1 !_I!)Do @Set "_S=!_S!!_V:~%%i,1!"%\n: Build Left half of output string =%
  293.      @Set "_S=!_S!!_P!"%\n: Append unmirrored component if defined =%
  294.      @For /l %%i in (!_O! -1 0)Do @(%\n: Append mirror of string enacting replacements =%
  295.       @If "!_V:~%%i,1!"==";" @Set "_S=!_S! "%\n%
  296.       @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%
  297.      )%\n%
  298.      @Set "_M="%\n: nul _M var used to join horizontal repetitions =%
  299.      @For /l %%i in (1 1 !_X!)Do @Set "_M=!_M!!_S!"%\n: append horizontal repetitions =%
  300.      @If Defined _M @Set "_S=!_M!"%\n: Swap out appended string if defined =%
  301.      @Set "_Fc="%\n%
  302.      @If Defined [F] @For /l %%i in (0 1 %MaxLen%)Do @If not "!_S:~%%i,1!"=="" @(%\n: define vertical mirror of substring enacting replacements =%
  303.       @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%
  304.      )%\n%
  305.      @For /l %%i in (1 1 !_Y!)Do @(%\n%
  306.       @Echo(!_S!%\n: repeat string vertically =%
  307.      )%\n%
  308.      @If Defined [F] @(@If not Defined _F @(@Set "_F=!_Fc!")Else @Set "_F=!_Fc!!LF!!_F!")%\n: Append vertical Mirror =%
  309.     )%\n%
  310.     @If Defined [F] @Echo(!_F!%\n%
  311.     @Del "%~dpn0_In.~tmp" 2^> nul%\n%
  312.    )%\n: remove the temp file used. =%
  313.    @Endlocal%\n: Ends the local environment if args supplied. =%
  314.   )Else @Endlocal%\n: Ends the local environment if no args supplied to macro. =%
  315.  )Else @Setlocal ENableDelayedExpansion ^& @Set Mirror.Input=
  316.  
  317. :#====================== |  $rStr MACRO Definition. Author - T3RRY  | =====================
  318. :!!| $rStr Args:         Description:
  319. :!!|
  320. :!!|  /L Int            : Length of each Substring [MANDATORY] - At least one length must be supplied.
  321. :!!|  /L Int Int Int    : Varying Lengths may be provided for each Substring
  322. :!!|                      by supplying the length for the corresponding iteration.
  323. :!!|                      /R Iterations is defined as the number of lengths provided.
  324. :!!|   /Mod Int IntSum  : Supply a Range for a Random Length at provided Index.
  325. :!!|                       - Example: Two part string Part 1 = 5 characters, Part 2 = 7-15 characters:
  326. :!!|                          /L 5 .  /Mod :0 9+7 /D :
  327. :!!|                         - OVERIDES /L 5 . TO /L 5 [RandomInt 7-15]
  328. :!!|                       * Modifier value should be at same index of /Mod SubArgs as '.' is in /L:SubArgs
  329. :!!|                         - Use 0 values for Modifier list to retain /L lengths at original index.
  330. :!!|
  331. :!!|  /Rep Int          : Number of Iterations to repeat pattern as an Integer
  332. :!!|                      - Use /Rep when all Iterations of pattern are to be same /L length
  333. :!!|
  334. :!!|  /V ReturnVar      : Define Supplied returnvar with generated String
  335. :!!|                          - If no return var is supplied, value will be stored in $rStr_RV
  336. :!!|
  337. :!!|  /A ReturnVar      : Append generated string to supplied return variable.
  338. :!!|
  339. :!!|  /P Pattern Subargs:
  340. :!!|     - Predefined   : ANM - English Letters in Upper and Lower case + 0~9 [ DEFAULT ]
  341. :!!|                    : ANL - English Letters in Lower case + 0~9
  342. :!!|                    : ANU - English Letters in Upper case + 0~9
  343. :!!|                    : AL  - English Letters in Lower case
  344. :!!|                    : AU  - English Letters in Upper case
  345. :!!|                    : N   - 0~9
  346. :!!|                    : H   - Hex String: ABCDEF0123456789
  347. :!!|
  348. :!!|     - Range        : Character Range  - Provide a range to use as the Character Set.
  349. :!!|                       - Example:     /P [3-w] = 3456789abcdefghijklmnopqrstuvw
  350. :!!|                       - Range Order: 0-9a-zA-Z ; Total Available Range: 0-Z
  351. :!!|
  352. :!!|     - Custom       : "Character String"
  353. :!!|                       - provide a custom string of characters to use. Example:
  354. :!!|                         /L 3 3  /P "-+@$^&()" /S 6 /D -
  355. :!!|
  356. :!!|  /S Int            : Supply the length of a Custom Pattern.
  357. :!!|
  358. :!!|  /D "Delim"        : Delim Character to use.
  359. :!!|  /D "Delim Delim"  : Supply Multiple Delims ; inserted after each corresponding iteration.
  360. :!!|  Delim Substitution: The following characters require substitution to use:
  361. :!!|                      - {FS} for / Forward-Slash ; {SC} for ; Semicolon
  362. :!!|                      - {AS} for * Asterisk      ; {CM} for , Comma
  363. :!!|                      - {EQ} for = Equals
  364. :!!|
  365. :!!|  /B "Delim Delim"  : Bookend the string with the supplied pair of Delims.
  366. :!!|
  367. :!!|  /O                : Output the Generated string to STDOUT
  368. :!!|
  369. :#========================================================================================
  370.  
  371. Rem $rStr Switches. Defined outside macro for readability and maintainance.
  372.  Set $rStr[Switches]="V" "A" "P" "L" "S" "R" "D" "O" "Mod" "B" "Rep"
  373.  
  374.  Set $rStr=For %%n in (1 2)Do if %%n==2 (                              %\n: CAPTURE ARG STRING =%
  375.   Set "$rStr[Syntax]=%\E%[33m!$rStr[args]!"%\n%
  376.   For /F "Tokens=1,2 Delims==" %%G in ('Set "$rStr_" 2^^^> nul')Do Set "%%~G=" %\n: RESETS ALL MACRO INTERNAL VARS =%
  377.   If not "!$rStr[args]:* /=!" == "!$rStr[args]!" (                              %\n: BUILD $rStr.Args[!$rStr_arg[i]!] ARRAY IF ARGS PRESENT =%
  378.    Set "$rStr_leading.args=!$rStr[args]:*/=!"                                   %\n: SPLIT ARGS FROM SWITCHES =%
  379.    For /F "Delims=" %%G in ("!$rStr_leading.args!")Do Set "$rStr_leading.args=!$rStr[args]:/%%G=!"%\n%
  380.    Set ^"$rStr[args]=!$rStr[args]:"=!"                                          %\n: REMOVE DOUBLEQUOTES FROM REMAINING ARGSTRING - SWITCHES =%
  381.    Set "$rStr_arg[i]=0"                                                            %\n: ZERO INDEX FOR ARGS ARRAY =%
  382.    For %%G in (!$rStr_leading.args!)Do (                                           %\n: BUILD ARGS ARRAY =%
  383.     Set /A "$rStr_arg[i]+=1"%\n%
  384.     Set "$rStr_arg[!$rStr_arg[i]!]=%%~G"%\n%
  385.     For %%i in ("!$rStr_arg[i]!")Do (                                              %\n: SUBSTITUTE THE FOLLOWING POISON CHARACTERS =%
  386.      Set "$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{SC}=;!"%\n%
  387.      Set "$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{QM}=?!"%\n%
  388.      Set "$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{FS}=/!"%\n%
  389.      Set "$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{AS}=*!"%\n%
  390.      Set "$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{EQ}==!"%\n%
  391.      Set ^"$rStr_arg[%%~i]=!$rStr_arg[%%~i]:{DQ}="!"%\n%
  392.   ))) Else (                                                                           %\n: IF NO ARGS REMOVE DOUBLEQUOTES FROM ARGSTRING - SWITCHES =%
  393.    Set ^"$rStr[args]=!$rStr[args]:"=!"%\n%
  394.    Set "$rStr_Arg[1]=!$rStr[args]!"%\n%
  395.    Set "$rStr_Arg[i]=1"%\n%
  396.   )%\n%
  397.   For /L %%L in (2 1 4)Do If "!$rStr_LastSwitch!" == "" (%\n%
  398.    If "!$rStr[args]:~-%%L,1!" == " " Set "$rStr_LastSwitch=_"%\n%
  399.    If "!$rStr[args]:~-%%L,1!" == "/" (                                              %\n: FLAG LAST SWITCH TRUE IF NO SUBARGS ; FOR SWITCHES UP TO 3 CHARCTERS LONG =%
  400.     For /F "Delims=" %%v in ('Set /A "%%L-1"')Do Set "$rStr_Switch[!$rStr[args]:~-%%v!]=true"%\n%
  401.     Set "$rStr[args]=!$rStr[args]:~0,-%%L!"%\n%
  402.     Set "$rStr_LastSwitch=_"%\n%
  403.    )%\n%
  404.   )%\n%
  405.   For %%G in ( %$rStr[Switches]% )Do If not "!$rStr[args]:/%%~G =!" == "!$rStr[args]!" (%\n: SPLIT AND ASSIGN SWITCH VALUES =%
  406.    Set "$rStr_Switch[%%~G]=!$rStr[args]:*/%%~G =!"%\n%
  407.    If not "!$rStr_Switch[%%~G]:*/=!" == "!$rStr_Switch[%%~G]!" (%\n%
  408.     Set "$rStr_Trail[%%~G]=!$rStr_Switch[%%~G]:*/=!"%\n%
  409.     For %%v in ("!$rStr_Trail[%%~G]!")Do (%\n%
  410.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]: /%%~v=!"%\n%
  411.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:/%%~v=!"%\n%
  412.     )%\n%
  413.     Set "$rStr_Trail[%%~G]="%\n%
  414.     If "!$rStr_Switch[%%~G]:~-1!" == " " Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:~0,-1!"%\n%
  415.     If "!$rStr_Switch[%%~G]!" == "" Set "$rStr_Switch[%%~G]=true"%\n%
  416.     If not "!$rStr_Switch[%%~G]!" == "" If not "!$rStr_Switch[%%~G]!" == "true" (%\n%
  417.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:{SC}=;!"%\n%
  418.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:{QM}=?!"%\n%
  419.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:{FS}=/!"%\n%
  420.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:{AS}=*!"%\n%
  421.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:{EQ}==!"%\n%
  422.      Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]!"%\n%
  423.    ))%\n%
  424.    If "!$rStr_Switch[%%~G]:~-1!" == " " Set "$rStr_Switch[%%~G]=!$rStr_Switch[%%~G]:~0,-1!"%\n%
  425.    Set "$rStr[RV]="%\n%
  426.   )%\n: ACTION SWITCH ASSESSMENT BELOW. USE CONDITIONAL TESTING OF VALID SWITCHES OR ARGS ARRAY TO ENACT COMMANDS FOR YOUR MACRO FUNCTION =%
  427.   Set "$rStr_Var=$Rstr_RV"%\n%
  428.   If not "!$rStr_Switch[L]!" == "true" If not "!$rStr_Switch[L]!" == "" (%\n%
  429.    For %%G in ( Switch[L] Switch[B] Switch[D] Switch[Mod] )Do If not "!$rStr_%%G!" == "true" If not "!$rStr_%%G!" == "" (%\n%
  430.     Set "$rStr_%%G[i]=0"%\n%
  431.     For %%H in (!$rStr_%%G!)Do (%\n%
  432.      Set /A "$rStr_%%G[i]+=1"%\n%
  433.      Set "$rStr_%%G[!$rStr_%%G[i]!]=%%H"%\n%
  434.      For %%q in (Switch[B] Switch[D])Do if "%%q" == "%%G" (%\n%
  435.       Set "rStr_dSub=%%H"%\n%
  436.       Set "rStr_dSub=!rStr_dSub:{AS}=*!"%\n%
  437.       Set "rStr_dSub=!rStr_dSub:{SC}=;!"%\n%
  438.       Set "rStr_dSub=!rStr_dSub:{CN}=:!"%\n%
  439.       Set "rStr_dSub=!rStr_dSub:{CM}=,!"%\n%
  440.       Set "$rStr_%%G[!$rStr_%%G[i]!]=!rStr_dSub!"%\n%
  441.      )%\n%
  442.      If "%%G" == "Switch[Mod]" If not "%%H" == "0" Set /A "$rStr_Switch[L][!$rStr_%%G[i]!]=!random! %% %%H "%\n%
  443.    ))%\n%
  444.    If "!$rStr_Switch[P]!" == "" Set "$rStr_Switch[P]=ANM" %\n%
  445.    If "!$rStr_Switch[P]!" == "true" Set "$rStr_Switch[P]=ANM" %\n%
  446.    If /I "!$rStr_Switch[P]!" == "ANM" ( Set "$rStr_CharSet=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ^& Set "$rStr_pSize=62" )%\n%
  447.    If /I "!$rStr_Switch[P]!" == "ANU" ( Set "$rStr_CharSet=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ^& Set "$rStr_pSize=36" )%\n%
  448.    If /I "!$rStr_Switch[P]!" == "ANL" ( Set "$rStr_CharSet=abcdefghijklmnopqrstuvwxyz0123456789" ^& Set "$rStr_pSize=36" )%\n%
  449.    If /I "!$rStr_Switch[P]!" == "AM" ( Set "$rStr_CharSet=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ^& Set "$rStr_pSize=52" )%\n%
  450.    If /I "!$rStr_Switch[P]!" == "AL"  ( Set "$rStr_CharSet=abcdefghijklmnopqrstuvwxyz" ^& Set "$rStr_pSize=26" )%\n%
  451.    If /I "!$rStr_Switch[P]!" == "AU"  ( Set "$rStr_CharSet=ABCDEFGHIJKLMNOPQRSTUVWXYZ" ^& Set "$rStr_pSize=26" )%\n%
  452.    If /I "!$rStr_Switch[P]!" == "N"   ( Set "$rStr_CharSet=1234567890" ^& Set "$rStr_pSize=10" )%\n%
  453.    If /I "!$rStr_Switch[P]!" == "H"   ( Set "$rStr_CharSet=ABCDEF0123456789" ^& Set "$rStr_pSize=16" )%\n%
  454.    If not "!$rStr_Switch[P]:*]=!." == "!$rStr_Switch[P]!." (%\n: facilitate custom P [start-end] Pattern Range =%
  455.     For /F "Tokens=1,2 Delims=[-]" %%1 in ("!$rStr_Switch[P]!")Do (%\n%
  456.      Set "$rStr_pSize="^& Set "$rStr_Start=%%1"%\n%
  457.      For %%c in ( 0 1 2 3 4 5 6 7 8 9 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 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 (%\n%
  458.       If "%%c" == "%%1" (%\n%
  459.        Set "$rStr_CharSet=%%c"%\n%
  460.        Set "$rStr_pSize=0"%\n%
  461.       )%\n%
  462.       If "%%c" == "%%2" (%\n%
  463.        Set "$rStr_CharSet=!$rStr_CharSet!%%c"%\n%
  464.        Set "$rStr_Start="%\n%
  465.        Set /A "$rStr_pSize+=1"%\n%
  466.       )%\n%
  467.       If not "!$rStr_CharSet!" == "%%c" If not "!$rStr_Start!" == "" (%\n%
  468.        Set "$rStr_CharSet=!$rStr_CharSet!%%c"%\n%
  469.        Set /A "$rStr_pSize+=1"%\n%
  470.    ))))%\n%
  471.    If "!$rStr_CharSet!" == "" (%\n%
  472.     Set "$rStr_CharSet=!$rStr_Switch[P]!"%\n%
  473.     If not "!$rStr_Switch[S]!" == "" If not "!$rStr_Switch[S]!" == "true" (Set "$rStr_pSize=!$rStr_Switch[S]!")%\n%
  474.     If "!$rStr_pSize!" == "" (%\n%
  475.      For /L %%i in (0 1 200) Do If "!$rStr_pSize!" == "" If "!$rStr_Switch[P]:~%%i,1!" == "" ( Set /A "$rStr_pSize=%%i-1" )%\n%
  476.    ))%\n%
  477.    If "!$rStr_Switch[R]!" == "" Set "$rStr_Switch[R]=!$rStr_Switch[L][i]!"%\n%
  478.    If not "!$rStr_Switch[Rep]!" == "" (%\n%
  479.     Set "$rStr_Switch[D]=!$rStr_Switch[D]:{SC}=;!"%\n%
  480.     Set "$rStr_Switch[D]=!$rStr_Switch[D]:{CM}=,!"%\n%
  481.     Set "$rStr_Switch[D]=!$rStr_Switch[D]:{AS}=*!"%\n%
  482.     Set "$rStr_Switch[R]=!$rStr_Switch[Rep]!"%\n%
  483.     For /L %%i in (1 1 !$rStr_Switch[R]!)Do (%\n%
  484.      Set "$rStr_Switch[L][%%i]=!$rStr_Switch[L]!"%\n%
  485.      Set "$rStr_Switch[D][%%i]=!$rStr_Switch[D]!"%\n%
  486.      If "%%i" == "!$rStr_Switch[Rep]!" Set "$rStr_Switch[D][%%i]="%\n%
  487.    ))%\n%
  488.    For /L %%i in (1 1 !$rStr_Switch[R]!) Do (%\n%
  489.     FOR /L %%n IN (1 1 !$rStr_Switch[L][%%i]!)Do (%\n%
  490.      For /F "delims=" %%c In ( 'SET /A "!RANDOM! %% !$rStr_pSize!"' )Do (%\n%
  491.       Set "$rStr[RV]=!$rStr[RV]!!$rStr_CharSet:~%%c,1!"%\n%
  492.     ))%\n%
  493.     Set "$rStr[RV]=!$rStr[RV]!!$rStr_Switch[D][%%i]!"%\n%
  494.    )%\n%
  495.    Set "$rStr[RV]=!$rStr_Switch[B][1]!!$rStr[RV]!!$rStr_Switch[B][2]!"%\n%
  496.    If not "!$rStr_Switch[A]!" == "" ( Set "$rStr_Var=!$rStr_Switch[A]!" ^& For /F "Delims=" %%v in ("!$rStr_Switch[A]!")Do Set "$rStr[RV]=!%%v!!$rStr[RV]!")%\n%
  497.    If not "!$rStr_Switch[V]!" == "" ( Set "$rStr_Var=!$rStr_Switch[V]!" ^& Set "!$rStr_Switch[V]!=!$rStr[RV]!" 2^> nul) %\n%
  498.    If "!$rStr_Switch[O]!" == "true" Echo(!$rStr[RV]!%\n%
  499.   )Else (Echo( /L Integer Required^^! )%\n%
  500.  ) Else Set $rStr[args]=
  501.  
  502. Exit /b 0
Add Comment
Please, Sign In to add comment