How they paste the right number of clips in its batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

How they paste the right number of clips in its batch

#1 Post by pieh-ejdsch » 13 Nov 2016 15:58

if the Level not correct your Batch will Crash.

this script completely runs

Code: Select all

:SetEchoBack
@setlocal
@ :: Liest ob ECHO ON oder OFF geschalten ist um Variablen zu setzen
@(
echo>"%temp%\isOn.Ft"
for /f "usebackq tokens=2 delims=()" %%E in ("%temp%\isOn.FT") do @set "EchoBack=echo %%E &"
del "%temp%\isOn.Ft"
set prompt=$G$S
)
) some tests
echo off
if defined debug echo on
(echo hallo in der Klammer
::
rem in der Klammer & weiter hier
rem )^
echo hinter rem Klammer
:etwas geschrieben & weiter gehts
echo abc
)
echo hinter der Klammer zu
(((
rem
)))

(
   :rem
:
) ,;=
echo hinter der leeren Klammer
) (@echo Klammer zu hinter LEVEL 0
rem neue Klammer auf
(
@^   
) & ,;=)
) ,;=) ,;=) ,;=) pause
) ^
 ) &echo) 0&
,;=)

 ,;=   ) & <ReadNotThisFile  >notCreated && :no Mark || not Executed " " set echo xy | echo nothing
)

) define LF as a Line Feed (newline) character
(
set ^"LF=^

" )  Above empty line is required - do not remove
) &echo rem this will check for correct closing

:: define a newline with line continuation
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"

 rem this will END from 0 to 30 Parenths
set PE30=@(@%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%
) %\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%
) %\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%)%\n%
)

set ^"\A=)^^^&@set/ax+=1^^^%LF%%LF%^%LF%%LF%^^"


 rem this will END from 0 to 100 Parenths (or many to) and check failNumber
@set PE=@(@%\n%)%\n%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%%\A%
)^&@set/ax+=1

call call call call set ")=^^^^^" &rem create 80x

set ^)=@(@%\n%)%\n%
%):^=2^>nul set/aX+=1)^|^|set/aX-=1^&%


set x=0
echo vor den klammern
(((
(

%=;) ( abcdefg )=%

(
%PE% &echo nothing
echo %x% ^) missing

),;=)
) &)

set x=0
(((((
(((((
rem 10 klammern
(((((
rem 15 klammern
(((((%)% %)%

echo %x%
set x=0
(((((((((((((((((((((((((((((((((
%)%
echo %X%
set x=0

(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
for /f %%i in ("1 2 3 4 5 6 7") do %)% %)%
echo %x%
set x=0

(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((
for /l %%i in (1 1 20 ) do %pe%
%pe%&%pe%&%pe%
echo %x%
 ,;=) & ,;=) & ,;=) & ,;=) & ,;=) & ,;=) & ,;=) & ,;=) & ,;=) & ,;=)

)= & echo xyz

) @^
) @^
) @^
 echo 3at

set "END=call ) &"

(

((
rem in Drei geoeffneten Klammern
echo xyz
%PE30% nothing to do
((
rem zwei geoeffnete Klammern

) &call ) & echo rem "" ^^ ^^ ^^ ^^ vier doppelte Escape ) &call )
(
rem eine geoeffnete Klammer
 rem check
call echo " 1^ 2^^ 3^^^"  ^^
call call echo " 1^ 2^^ 3^^^"  ^^
call call call echo " 1^ 2^^ 3^^^"  ^^ )
%PE30%
) rem keine Anzeige
) rem keine 2. Anzeige

echo vor dem Schluss
echo a^
 b c^
) & echo ^"extraZeile^
 echo keine extra Zeile
%PE%
set x=0
(((((((((( (((((((((( (((((((((( (((((((((( (((((((((( ((((((((((

for /l %%l in (1 1 10) do (echo %%l
 for /l %%x in (1 1 2) do %PE%
%PE30% &%PE30%&
echo %x% ^) Missing

:checkCMDline
:: setzt eine Variable CMDPause wenn im Batchmodus
@echo off
setlocal disabledelayedexpansion
 rem CMD-Kontex ?
set "CMDPause=%~f0"
set "CMDPause=%CMDPause:\=\\%"
set "CMDPause=%CMDPause:.=\.%"
setlocal enabledelayedexpansion
for /f delims^= %%i in ("!CMDcmdLine!") do endlocal &set "CMDPin=%%i"
cmd /von /c "echo !CMDPin!" |findstr /irc:"cmd .*\/c \"\"%CMDPause%\" .*\"" /c:"cmd\.exe .*\/c \"\"%CMDPause%\" .*\"" >nul
endlocal
echo on
if not errorlevel 1 set "CMDPause=pause &"
if errorlevel 1 set "CMDPause="
%EchoBack%
%CMDPause% exit /b

:checkEchoOn
%= @rem :: Liest ob ECHO ON oder OFF geschalten ist um Variablen zu setzen =%
@(
rem ^%Mon% Zeilen bei Echo on auf REM umschalten
echo>"%temp%\isOn.Ft"
< "%temp%\isOn.Ft" find "ON" >nul && set "Mon=rem" || set "Mon=echo("
del "%temp%\isOn.Ft"
exit /b
%PE%


the number of the round Clips (Parenth ?) is determined in single lines without error.
The number is worked [%X%] out, thus this can be created the Script with the right number.

Phil

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How they paste the right number of clips in its batch

#2 Post by penpen » 14 Nov 2016 04:58

Sweet script:
I like it :D !

Here are some details:
1) If there is no corresponding opening parenthesis, a closing parenthesis stops the parser to parse the rest of the line:

Code: Select all

) this | does & not && do || anything, if there is no opening parenthesis

So the following just does nothing if there is no corresponding opening parenthesis:

Code: Select all

)&set/a x+=1
But if there is a corresponding parenthesis, then it increases the variable x by 1 (if x is no "batch style" number, then it is assumed to be zero).

This results in the first method of closing and counting (up to 5) parenthesis:

Code: Select all

@setlocal
set "x=0"
(((
(@
)
)&set/a x+=1
)&@set/a x+=1
)&@set/a x+=1
)&@set/a x+=1
)&@set/a x+=1
set "x"
@endlocal
(Also note the effect of the at character ('@').)

2)Two pipes "||" form a conditional instruction:

Code: Select all

command1 || command2
The "command2" is executed only if the return value of "command1" is != 0.

If there is no corresponding opening parenthesis, then this command returns some value != 0:

Code: Select all

set/a X+=1)
If there is a corresponding parenthesis, then the above command just increases variable x by 1.

The reason why "x+=1" is executed when there is a missing corresponding parenthesis is a little bit tricky:
"1" is a complete term, and so "x+=1" is a complete accumulated assignemnt, so it is executed;
the ")" then raises an exception (after the preceeding expression is executed) and triggers the error "Missing operand.".

You then could use " 2>nul " to 'hide' the error, and subtract 1 in case an error occured (== unbalanced ')' char detected) by using:

Code: Select all

set/a X+=1) 2>nul ||set /a X-=1


This results in the second method of closing and counting (up to 5) parenthesis:

Code: Select all

@setlocal
set "x=0"
((
(@
)
set/a X+=1) 2>nul ||set /a X-=1&^
set/a X+=1) 2>nul ||set /a X-=1&^
set/a X+=1) 2>nul ||set /a X-=1&^
set/a X+=1) 2>nul ||set /a X-=1&^
set/a X+=1) 2>nul ||set /a X-=1

set "x"
@endlocal


penpen

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: How they paste the right number of clips in its batch

#3 Post by pieh-ejdsch » 16 Nov 2016 10:26

this create macro I have solved about a temporary file.
With interlocking loops and several repetitions this it was added too much.
The displays of missing to closing clips occur now exactly.

Code: Select all

:macro.checkParenthesis
:: FIRST DEFINE THE MACRO with Tempfile
:: VAR # = Number of Failed )
:: VAR ) = macro for Check
@for %%A in ("%temp%\Pfile.cmd") do @(
@(
echo ^@(set LF=^^
echo(
echo(^)
echo @set ^^^"\n=^^^^^^%%LF%%%%LF%%^^%%LF%%%%LF%%^^^^"
echo @set ^^^)=@^(@%%\n%%
for /l %%i in (0 1 50) do @echo(^)^^^&@set/a#=%%i%%\n%%
echo(^)
) >%%A
call %%A
del %%A
if /i "%~0" equ ":macro.checkParenthesis" exit /b
)
:: END macro.checkParenthesis


Code: Select all

@echo off
call macro.checkParenthesis.cmd
(for /l %%i in (1 1 20) do (
  for /l %%j in (1 1 3) do (
 (
  (
(
%)% &echo nothing
echo %#% ^) missing
pause


Phil

Post Reply