GlobalAccessSoftware icon

utility3.bat

GlobalAccessSoftware | PRO | 11/16/23 05:59:57 AM UTC | 1 ⭐ | 14362 👁️ | Never ⏰ | []
Batch |

12.81 KB

|

Software

|

1 👍

/

0 👎

 
 
::: RC9 :::
 
 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: Utility3.bat splitout from Errorhandling.bat v8.6.8.94  :::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: :revchars <string revstrReturned, string str2rev>                 :::
::: :makeline <string line2Fill, string padChars, string strToPadTo>  :::
::: :padder <string toRtn, int lengthRequired, string padchars>       :::
::: :getspcs <string spcs2Return, int gap>                            :::
::: :strlen <int sizeOfstr2rtn, string str2measure>   WORKING!        :::
::: :overload <no parms, no args, no returns, cash only please>       :::
::: :getgap <string gap, string line, string chars, string msg>       :::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
  if not defined vers set vers=v8.7.0.10 20231108073214 by -JpE-
 
:alt <string 2Return, string calling, string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7>
  setlocal & set "rtn0=%~1" & set "calling=%~2" & set "arg1=%~3" & set "arg2=%~4" & set "arg3=%~5" & set "arg4=%~6" & set "arg5=%~7" & set "arg6=%~8" & set "arg7=%~9"
  if not defined calling goto altx
  if %testwell% gtr 4 goto altx
  ::: Jump to :::
  if "%calling:~0,1%" neq ":" goto alt0
  ::: altN where N is the number of ^ args being passed.
  if "%calling%" equ ":revchars" call %calling% rtn0 "%arg1%"
  if "%calling%" equ ":makeline" call %calling% rtn0 "%arg1%" "%arg2%"
  if "%calling%" equ ":padder" call %calling% rtn0 %arg1% %arg2%
  if "%calling%" equ ":getspcs" call %calling% rtn0 %arg1%
  if "%calling%" equ ":strlen" call %calling% rtn0 "%arg1%"
  if "%calling%" equ ":overload" call %calling%
  if "%calling%" equ ":overload" set "rtn0= "
  if "%calling%" equ ":middleman" call %calling% "%arg1%" "%arg2%"
  if "%calling%" equ ":middleman" set "rtn0= "
  endlocal & set "%~1=%rtn0%"
  exit /b
 
 
  ::: All vars are global from above or below same namespace for all alts,
  ::: But not the functions below the last alt. They are sealed.
 
::: for calls without a calling, or arg1,2,3,4,5
:altx
if %testwell% gtr 2 set txt=Hello New World-x!
if %testwell% gtr 2 echo . & echo alt-x says: & echo %txt%
if %testwell% gtr 2 echo . & pause & echo .
if not defined calling set calling=Hello New World-0
  if defined calling goto alt0
::: note: unindented testcode vs indented code.
  ::: Then finish the :altx function below.
  
  ::: AND... end like... below from the "goto" of all alt.
  endlocal & set "%~1=%txt%" & set "%~2=%calling%"
  exit /b %errorlevel%
 
 
::: with a calling not begun with a colon and no other args.
:alt0
if %testwell% gtr 2 echo . & echo calling says %calling% & echo .
REM if %testwell% gtr 2 pause & echo .
if %testwell% gtr 2 if not defined arg1 set arg1=Hello New World-1
  if defined arg1 goto alt1
::: note: unindented testcode vs indented code.
  ::: Then finish the :alt0 function below.
  
  ::: AND... end like... below from the "goto" of all alt.
  endlocal & set "%~1=%calling%" & set "%~2=%arg1%"
  exit /b %errorlevel%
  
 
::: calling w/o colon; with 1 arg
:alt1
if %testwell% gtr 2 echo . & echo arg1 is %arg1% & echo .
REM if %testwell% gtr 2 pause & echo .
if %testwell% gtr 2 if not defined arg2 set arg2=Hello New World-2!
  if defined arg2 goto alt2
::: note: unindented testcode vs indented code.
  ::: Then finish the :alt1 function below.
  
  ::: AND... end like... below from the "goto" of all alt.
  endlocal & set "%~1=%arg1%" & set "%~2=%arg2%"
  exit /b %errorlevel%
  
  
::: calling w/o colon; with 2 args
:alt2 <string calling, string arg1, string arg2>
if %testwell% gtr 2 echo . & echo arg2 is %arg2% & echo .
REM if %testwell% gtr 2 pause & echo .
if %testwell% gtr 2 if not defined arg3 set arg3=Hello New World-3!
  if defined arg3 goto alt3  
::: note: unindented testcode vs indented code.
  REM if defined arg4 goto alt4
  ::: Then finish the :alt3 function below instead of returning back 1 level.
  
  ::: AND... end like... below from the "goto" of all alt.
  endlocal & set "%~1=%arg1%" & set "%~2=%arg2%"
  exit /b %errorlevel%
  
 
::: calling w/o colon; with 3 args
:alt3
if %testwell% gtr 3 echo . & echo arg2 is %arg2% & echo .
if %testwell% gtr 4 if not defined arg4 set "arg4=Hello New World-4!"
  if defined arg4 goto alt4
  call :getgaps spc1 spc2 "%arg1%" "%arg2%" "%arg3%"
  endlocal & set "%~1=%spc1%" & set "%~2=%spc2%"
  exit /b %errorlevel%
 
 
::: calling w/o colon; with 4 args
:alt4
if %testwell% gtr 2 echo . & echo arg4 is %arg4% & echo .
if %testwell% gtr 2 if not defined arg5 set "arg5=Hello New World-5!"
  if defined arg5 call :alt5
  ::: note: unindented testcode vs indented code.
  REM if defined arg5 goto alt5
  ::: Then finish the :alt4 function below instead of returning back 1 level.
if %testwell% gtr 1 echo . & echo arg1==%arg1%, arg2==%arg2%, arg3==%arg3%, arg4==%arg4%
if %testwell% gtr 1 pause & echo .
  call :exception1 "%arg1%" "%arg2%" "%arg3%" "%arg4%"
if %testwell% gtr 0 echo Back from exception1 & echo . & pause & echo .  
  ::: AND... end like... below from the "goto"
  endlocal & set "%~1=0" & set "%~2=1"  
  exit /b %errorlevel%
 
 
::: calling w/o colon, with 5 args.
:alt5
if %testwell% gtr 2 echo . & echo arg5 is %arg5% & echo .
if %testwell% gtr 2 if not defined arg6 set "arg6=You have reached alt6, there is one more levels available currently."
  if defined arg6 call :alt6
if %testwell% gtr 2 echo . & echo %arg6% & echo .
  ::: Then finish the :alt5 function below instead of returning back 1 level.
  
if %testwell% gtr 2 pause & echo .
  ::: AND... end like... below from the "goto"
  rem endlocal & set "%~1=%arg5%" & set "%~2=%arg6%"
  exit /b %errorlevel%
 
 
::: calling w/o colon, with 6 args.
:alt6
if %testwell% gtr 2 echo . & echo arg6 is %arg6% & echo .
if %testwell% gtr 2 if not defined arg7 set "arg7=This is alt7, there is no more above this."
  if defined arg7 call :alt7
if %testwell% gtr 2 echo . & echo %arg7% & echo .
  ::: Then finish the :alt6 function below instead of returning back 1 level.
  
if %testwell% gtr 2 pause & echo .
  ::: AND... end like... below from the "goto"
  rem endlocal & set "%~1=%arg5%" & set "%~2=%arg6%"
  exit /b %errorlevel%
 
 
::: calling w/o colon, with 7 args.
:alt7
if %testwell% gtr 2 echo . & echo arg7 is %arg7% & echo .
if %testwell% gtr 2 if not defined arg8 set "arg8=You've reached alt7, there are no provisions for more than 7 args."
if %testwell% gtr 2 echo . & echo %arg8% & echo .
  ::: Then finish the :alt7 function below instead of returning back 1 level.
  
  ::: AND... end like... below from the "goto"
  rem endlocal & set "%~1=%arg5%" & set "%~2=%arg6%"
  exit /b %errorlevel%
 
::: End of alt namespace, the below are all isolated functions.
 
 
::: Reverse a string arg and return reversed string.
:revchars <string revstrReturned, string str2rev>
  setlocal & set str=%~2
  if not defined sizer set sizer="%bats%\string_length.bat"
  if not exist %sizer% echo . & echo %sizer% not found. & echo Error 47 & echo . & pause & echo . & exit /b
  call %sizer% char5 str
  set rev=
  for /l %%n in (1,1,%char5%) do call :forloop1
  endlocal & set "%~1=%rev%"
  exit /b %errorlevel%
:forloop1
    set ltr=%str:~-1%
    set str=%str:~0,-1%
    set "rev=%rev%%ltr%"
    exit /b %errorlevel%
 
 
::: To remain generic, we'll be using it a lot.
:makeline <string line2Fill, string padchars, string strToPadTo>
  setlocal & set "txt3=%~3" & set "padchars=%~2"
  call :strlen pad "%padchars%"
  call :strlen len "%txt3%"
  if %pad% equ 0 if %len% equ 0 set line=WHO CALLED YOU?
  if %pad% equ 0 if %len% equ 0 (
    echo . & echo %line% & echo .
    pause & echo . & pause & echo . & goto sorry )
  set /a size8=((2 + %len% + %pad% * 2)/%pad%)
  :while
    set /a s8=(%size8% * %pad%)
    set /a g1=(%len% + 2 + (2 * %pad%))
    if %g1% gtr %s8% set /a size8+=1 
    if %g1% gtr %s8% goto while
  REM if %code2% equ 7 goto except
  REM if %code2% neq 7 
  call :padder line %size8% "%padchars%"
  :sorry
    endlocal & set "%~1=%line%"
    exit /b %errorlevel%
 
 
::: Pads string var to passed length with sent chars.
:padder <string toRtn, int lengthOfStringReqd, string padchars>
  setlocal & set "padchars=%~3" & set line1=
  for /l %%k in (1, 1, %~2) do ( call :loop3
    if %errorlevel% gtr 0 goto except
  )
  endlocal & set "%~1=%line1%"
  exit /b %errorlevel%
::: loop body for for-loop above.
:loop3
  set line1=%line1%%padchars%
  exit /b %errorlevel%
 
 
:except
  set /a code2=7 & set t1=The Exception was caught in :padder
  set s1=utility3.bat
  call :exception1 "%t1%" "%s1%" "%errorlevel%" "%code2%"
  exit
 
 
:exception1 <str text, str sender, int error, int code2>
  setlocal & set "t1=%~1" & set "s1=%~2" & set "e1=%~3" & set "c2=%~4"
  if not defined errr set errr="%bats%\ErrorHandling.bat"
  set ch=-/\-\/
  set t2=The ErrorLevel was %e1% and code2 == %c2%
  REM call :middleman "%ch%" "%t2%"
  echo . & if exist %errr% call %errr% "%t1%" "%s1%"
  echo . & pause & echo .
  endlocal & set /a code2=0
  exit /b %errorlevel%
  
 
:getspcs <string spcs2Return, int gap>
  setlocal & set /a "gap=%~2" & set sp=
  for /l %%i in (1, 1, %gap%) do call :addspace
  endlocal & set "%~1=%sp%"
  exit /b %errorlevel%
:addspace
  set nl= 
  set "sp=%sp%%nl%"
  exit /b %errorlevel%
 
 
:strlen <int sizeOfstr2rtn, string str2measure>
  setlocal & set str=%~2
  if not defined sizer set sizer="%bats%\string_length.bat"
  if exist %sizer% call %sizer% size str
  if not exist %sizer% echo . & echo Can't find %sizer% & echo .
  endlocal & set "%~1=%size%"
  exit /b
 
 
:overload
  echo .
  echo Years beyond 2147483647 are not calculable by this program,
  echo ask for an update. I'd just have to use another 32 bit register
  echo beyond that, to raise it by another order of this magnitude.
  exit /b
 
 
::: An All-In-One Function. Though these calls
::: can still be used separately when desired.
:middleman <str chars, str msg>
  setlocal & set "ch=%~1" & set "ms=%~2"
  call :revchars rv "%ch%"
  call :makeline ln "%ch%" "%ms%"
  call :getgaps g1 g2 "%ln%" "%ch%" "%ms%"
  set "nl=%rv%%g1% %ms% %g2%%rv%" & echo .
  echo %ln% & echo %nl% & echo %ln% & echo .
  endlocal
  exit /b
 
 
::: default is 2, 1 on ea side of txt. which ^ is in the program already at display of these. So if anything more then we are adding that here.
:getgaps <str gap1, str gap2, str line, str chars, str msg>
  setlocal & set "line=%~3" & set "chars=%~4" & set "msg=%~5"
  call :strlen l3n "%line%"
  call :strlen k4d "%chars%"
  call :strlen m5g "%msg%"
  set /a gap0=(%l3n% - (%m5g% + (2 * %k4d%)) - 2)
  call :equalizer
  if %gap1% gtr 0 call :getspcs pad1 %gap1%
  if %gap2% gtr 0 call :getspcs pad2 %gap2%
  if %gap1% lss 1 set pad1=
  if %gap2% lss 1 set pad2=  
  endlocal & set "%~1=%pad1%" & set "%~2=%pad2%"
  exit /b %errorlevel%
 
 
  :::::::::::::::::::::::::::::::::::::::::::::::::
  ::: NOTE: Inside same domain as :getgaps <==< :::
  ::: if the gap is greater than 2 it can be    :::
  ::: within 1 of being equally divided between :::
  ::: the two sides of the text. by -JpE- 2310  :::
  ::: Therefore, if div by 2 isn't even add 1   :::
  ::: to one side, the 2nd here, & Rock-n-Roll! :::
  :::::::::::::::::::::::::::::::::::::::::::::::::
 
:: given: gap total as gap2 & w/ gap1 init; [above]
:: make as equal as possible. Odd on gap2 if over.
:: Remember: 1 spc on each side is already programatic.
:equalizer
  set /a gap1=0 & set /a gap2=0 & set /a divi=0 & set /a rmdr=0
  if %gap0% gtr 0 set /a divi=(%gap0%/2) & set /a rmdr=(%gap0% %% 2%)
  if %gap0% gtr 0 set /a gap1=%divi% & set /a gap2=%divi%
  ::  if it went evenly we're done. Else... if odd merely... add one to only one side. Herein, the 2nd side or far end of line b4 revchar.
  if %rmdr% gtr 0 set /a gap2+=1
  exit /b %errorlevel%
 
    :: More a conceptual Design challenge than coding.
    :: But if Num went into 2 oddly, AKA unevenly...
    :: we can therefore safely say that it's the
    :: even product above (from the even which is
    :: 1 less than it) plus 1 in each instance,
    :: with the extra 1 on the right, in gap2. (here)
  
      :: design NOTES: 1 is the only possible remainder when dividing odds by 2 as 2 would make another pair. So... 5/2 == 2 w/ rmdr of 1 over 2 or 1/2. Or, with this, unevenly split into 2 + 2+1 == 5 so we don't have to split the character in 2. lol. Now, with divisions by odd numbers > 1, the remainder is greater than that, up to denominator-1. 2/3rds, or 4/5ths, etc. Example, take the year (after Gregorian Calendar in 1753) and divide by 4, if there is no remainder it is a leap year. Magic? No, Math! 1 in 4 years are leap years. Every 4 years. Divide by 4, same same... no remainder, that's the 1. i.e. 3:1 odds it's not leap year.
  
 
 
  ::: 100% -JpE-
 
 
 
 
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎