Line continuation if for...do scripts

S

Stu Smith

Hey All. I have a pretty complex script that contains a
bunch of for...do loops. Is there a way to split the
lines to make it more readable? The example below is just
one line of this monster. It basically takes all the
matching files in a directory and compiles them. If the
executable is generated it increments a counter and if a
flag is set writes to a log otherwise it writes a fail
message to the log.

for %%F in (%LocalFormsSrcDir%\bas*.pll) do start /w
C:\orant\bin\ifcmp60 module_type=LIBRARY
module_access=FILE batch=YES window_state=MINIMIZE userid=%
ProdDBConnectString% module=%LocalFormsSrcDir%\%%~nxF
output_file=%LocalBinDir%\%%~nF && if exist %LocalBinDir%\%
%~nF.plx (set /A NumPllCompiled=NumPllCompiled + 1 & if %
FullLoggingFlag% == Yes echo Compiled %%F ... >> %
LogFile%.log) else (echo %%F Failed!! >> %LogFile%.log)
 
P

Paul R. Sadowski

You can put a caret ^ character at the end of the line to continue it.

However, be sure there are no space characters or any other whitespace
following the ^ character.

Line 1^
Line 1 continued^
Line 1 continued on line 3
Line 2
Line 3
 
M

Matthias Tacke

Stu Smith said:
Hey All. I have a pretty complex script that contains a
bunch of for...do loops. Is there a way to split the
lines to make it more readable? The example below is just
one line of this monster. It basically takes all the
matching files in a directory and compiles them. If the
executable is generated it increments a counter and if a
flag is set writes to a log otherwise it writes a fail
message to the log.

for %%F in (%LocalFormsSrcDir%\bas*.pll) do start /w
C:\orant\bin\ifcmp60 module_type=LIBRARY
module_access=FILE batch=YES window_state=MINIMIZE userid=%
ProdDBConnectString% module=%LocalFormsSrcDir%\%%~nxF
output_file=%LocalBinDir%\%%~nF && if exist %LocalBinDir%\%
%~nF.plx (set /A NumPllCompiled=NumPllCompiled + 1 & if %
FullLoggingFlag% == Yes echo Compiled %%F ... >> %
LogFile%.log) else (echo %%F Failed!! >> %LogFile%.log)

Assemble long commands in a var, use additional parenthes, after an
open parenthes continue on a new line, change the logic to use goto's
and call :Internalsub instead of stuffing all in a single line.
If you already use parenthes there is no need to use & to put the
following command on the same line.

HTH
 
S

Stu

That is a little tto complex for what I'm trying to do
(just trying to make the silly thing more readable).
Thanks for the advice though...
 
S

Stu

That seems to do it. I miss the white space but for now
it at least makes the script a bit more readable. Thanks
for the advice...
 
M

Matthias Tacke

Stu said:
That is a little tto complex for what I'm trying to do
(just trying to make the silly thing more readable).
Thanks for the advice though...
Really? Try this combination of Paul's and mine tips:

for %%F in (%LocalFormsSrcDir%\bas*.pll) do (
start /w C:\orant\bin\ifcmp60 ^
module_type=LIBRARY ^
module_access=FILE ^
batch=YES ^
window_state=MINIMIZE ^
userid=%ProdDBConnectString% ^
module=%LocalFormsSrcDir%\%%~nxF ^
output_file=%LocalBinDir%\%%~nF && if exist %LocalBinDir%\%%~nF.plx (
set /A NumPllCompiled=NumPllCompiled + 1
if %FullLoggingFlag% == Yes echo Compiled %%F ... >> %LogFile%.log
) else (
echo %%F Failed!! >> %LogFile%.log)
)
 
Top