From: kraai4712@iscsvax.uni.edu
Newsgroups: comp.sys.ibm.pc.misc
Subject: Please try this BATCH utility!  :-)
Date: 9 Oct 92 15:06:11 -0500
Organization: University of Northern Iowa

Since we're playing with small stuff here, I thought I'd solicit some
discussion about my BATCH FILE.  Of course, there is a hidden, insideous virus
in this batch file, and I will buy a drink for anyone who can find it and
convince me that the statement, "This is a lie." is meaningful.

Who cares?  Well, it's a nice way to observe batch-file recursion and the use
of some interesting batch file stuff.  The objective of the batch file is to
accept, as command-line params, a list of valid filespecs (with or w/o
wildcards), and to expand/copy them to the console one screen at-a-time.  After
each file is finished, the message, "End of 'whatever'" is typed, whereafter
the next valid file is found and sent to the screen.

I'd be thrilled for any discussion on:
        1)  Can this be shortened without losing functionality?
                (NOTE:  double-spaces/indents added for readability)
        2)  What functionality could be added to this and in this case
            size-be-darned -- with little knitting needles, of course.

I also promise not to bet pissed off if anyone flames me, I will just hunt you
down and shove bing cherries up your left nostril -- HAHAHAHAHAHAHAHAHAHA!!!!

DOC follows for those who need it ... ;-)

---BEGIN BATCH_FILE_FROM_HECK----------------------------------------------

@echo off
if not %1 == subroutine goto MAIN

if not exist %2 goto END
  type %2 | more
  echo End of %2
  pause
  goto END

:MAIN
  set unique=%0

:LOOP
  for %%f in (%1) do call %unique% subroutine %%f
  shift
  if not %1. == . goto LOOP

  set unique=

:END
--------------------------------------------------------------

Basically the file behaves one way if the first command-line parameter is the
string, "subroutine", and behaves another way if it isn't.

If it's behaving as a "main" program, it's expanding a command-line parameter
and passing it on (to itself, recursivly) to the subroutine.  After it expands
the first command-line parameter, it uses SHIFT and does a check to see if
there were any other command-line parameters, if there were, it goes back to
the expansion/calling routine until there are no command-line parameters left. 
This nicely sidesteps any question of the maximum number of command-line 
parameters available.

If it's behaving like a subroutine, it assumes it's got a filename as %2 and
sends the file to the console a page-at-a-time and then pauses.  The if-exist
clause tests for circumstances where a "hard" filename was passed to the
subroutine (that is with no wildcards) doesn't exist and exits the subroutine
cleanly.
--------------------------------------------------------------------------
jim kraai, undergrad, university northern iowa, kraai4712@iscsvax.uni.edu
--------------------------------------------------------------------------
All opinions are my own, but are | Your eyes are weary from staring at the
   hereby released to the public | CRT.  You feel sleepy.  Notice how
   domain for the furtherance of | restful it is to watch the cursor blink
      common sense and a general | Close your eyes.  The opinions stated
          improvement of dinner- | above are yours.  You cannot imagine
             party conversation. | why you ever felt otherwise.
Xref: sparky comp.sys.ibm.pc.misc:13628 comp.sys.ibm.pc.hardware:26841