label in the very last line. If the do-
nothing file CRLF.BAT is still avall-
able to DOS, the preceding program
may be considerably speeded up by
writing it in the following form:
:LABEL1
cFIRST PROCEDURE>
CR LF
:LABEL2
cSECOND PROCEDURE
CRLF

: LASTLABEL
cLAST PROCEDURE~

	Now, instead of searching the file
for ":EXIT", the program will directly
chain to CRLF and abruptly quit.

Using SHIFT

There are two qood uses for the

SIIIFT command: to allow an indefi-
nite number of command line para-
meters and to count. Suppose you
have a print formatter called
PRT.COM. You couid feed several
files to it with a batch file containing
the following:

FOR %%@ INt%1 %2 %3 %4 %5
%6 %7 8% 9%) DO PRT %ø/O@
This is fast enough, but is limited to
nine arquments. This little program
will accept unlimited arguments, us-
ing SHIFT:

:DO
IF %1@==@ GOTO ENDDO
PPT %1
SHIFT

	GOTO DO
;END0O
or quicker:
: PROC

IF %1@==@ GOTO ENDPROC
PRT %1
FOR %ø/O@ IN(SHIFT GOTO) DO
% % @ PROC
: EN DPROC

	This is the most general form that
will not execute if there are no argu-
ments. A shorter (and therefore fas-
ter) version of this basic loop may be
used, but this form will execute at
least once, even if there are no argu-
ments. Use it by all means if this
does not matter.

: LOOP
PRT %1
SHIFT

	IF NOT %~@==@ GOTO LOOP
or quicker:
; LOOP

PRT %1
FOR %%@ IN(SHIET IF) DO %ø/O@
NOT %1@==@ GOTO LOOP

	If we can use CRLF.BAT to break
out of the program, we can have the
best of both worlds.

: LOOP
IF %1@==@CHLF
PRT %1
FOR %%@ IN(SHIFT GOTO)

DO %%@ LOOP

	Soon we'll see a more advanced
application of this principle. You can
also use the command-line tokens as
items to be counted. Write
TEST. BAT:
ECHO C)FF
CLS
:DO

ECHO Display for token %1
Si IIFT
IF NOT %1~==@ GOTO DO

	Run TEST with severa} calls to see
this work.
TEST
TEST 1 2 3
TEST X X X
TEST NOW THREE WORDS
TEST 1 TWO 3 2+2 5 ~ 7 8 9 TEN 11

Batch procedures

You may want to create a complex
batch file to automate an obnoxious
procedure, but perhaps you don't
use it often enough to remember its
complex call syntax.

	The answer to this is to set the
batch file up so it will give you some
instruc~ions if called with no argu-
ments. For example, here is the start
of my batch program iDLOAD.BAT'
which permits unattended download-
ing of partitioned datasets from the
IBM mainframe, a procedure that
could take hours. The actual down-
load procedure is so slow that batch
file spend is a nealiaible factor. so

	..	.	.

		~",	~

nothing is compressed into FOR
loops here.
ECHO OFF
CLS
IF NOT ø~1@==@GOTO START

ECHO DOWN LOAD PARTITION6D
DATASETS FROM MAINFRAME
ECI1O

EC1 10 SYNTAX: DLOAD DSN DIR
MEMBER1 MEMBER2
MEMBER3 . . .

ECHO Where DSN is the fully
quallfied dataset name,

ECH~ DlB is the
destination subdirectory.

ECHO and MEMBERn
are any number of member
names.

	CRLF
: START
SET DSN=%1
SHIFT
SET DIR=%1
FOR % %@ IN(MD SHI FT) % %@ ~ %1
MD \%1 ~NUL
SHIFT
:DO

IF %1@==~? CRLF

cOOWNLOAD PROCEDURE~

SHI FT

GOTO DO

	Several techniques are used in this
program. If DLOAD is entered with
no arguments, the first IF statement
detects this, and the instructions are

echoed. When DLOAD is called with
arguments, the first variable is set to
%DSN% for later use by <download
procedure>, then is shifted away.
The second variable (now %1 ) is
stored as % DIR% and then creates
the desired subdirectory before
banishment by shifting. The 'mem-
bers' are shifted in turn into position
%1 by the loop, until they are all
usod up. Exits from the program are
by fast calls to CRLF.BAT, which was
created earlier. If the attempt to
make the subdirectory fails, perhaps
because the subdirectory aiready ex-
ists, the resulting error message will
be shu nted off to N U L.

Menus

Fig 1 shows a program to control
some settings for an Epson/lBM-type
printer. It will display a menu if cal-
led without arqument, but this menu
may be bypassed if the user knows
what to enter.

Calling batch files

Now we will see how we can call
another batch file and return from it,
as though it were a subroutine. If
you chain to another batch program,
that's it Ä there is no return. The
secret of true calls is the 'COM-
MAND'statement.

	'COMMAND' loads another copy of
part of COM MAN D.COM i nto mem-
ory and gives it control. This does
not consume as much memory as
IBM wouid have you believe, since it
does not load another copy of the
whole 28k or 40k COMMAND.COMÄ
it only loads another c~py of the
command pracessor which is about
4k. The new command processor
runs quite independently of the pre-
vious one.

	The command 'EXIT' purges the
currently executing command pro-
cessor and puts you back to the pre-
vious one. EXIT does nothing if en-
tered into the one and only original
command processor.

	It is not obvious what the use of
this is until you remember file re-
direction. What happens if the new
command processor takes its input
from a file? Try it by making a file
full of commands, ending with EXIT.
We'll call it GIZMO. (If you don't end
this file with EXIT you'll never return;
the computer will hang up for good.)
VOL

ECH~ This line is from

	the called file.
VER
EXIT

	Next create DRIVE.BAT and run it:
ECHO OFF
CLS
ECHO This line is from

the main program.

%l,

