Article 138850 of comp.os.vms:
Path: nntpd.lkg.dec.com!lead.zk3.dec.com!crl.dec.com!crl.dec.com!caen!newsxfer2.itd.umich.edu!newsfeed.internetmci.com!in2.uu.net!eco.twg.com!news
From: mike@%DCL-W-IVVERB, unrecognized command verb - check validity and spelling \HOSTNAME\.eco.twg.com (This space intentionally left blank)
Newsgroups: comp.os.vms
Subject: Re: Optimized DCL ??
Date: 26 Jan 1996 23:15:29 GMT
Organization: The Wollongong Group (East Coast Operations)
Lines: 267
Message-ID: <4ebnah$ec8@eco.twg.com>
References: <1996Jan16.234317@earth.medcolpa.edu> <4do5sr$om0@explorer.csc.com>
NNTP-Posting-Host: elwood.eco.twg.com

In article <4do5sr$om0@explorer.csc.com>, rkoehler@csc.com (Robert Koehler) writes:
>Andrew Brennan, Bween-at-large (brennan@earth.medcolpa.edu) wrote:
>:    [ second in a series of reposts ... local newsfeed difficulties ]
>
>:    I've been looking at 2000+ lines of DCL (mentioned in an earlier note) 
>:    and thinking that it could be optimized somehow.  We have an old version
        :
>:    Has anyone put together notes on optimizing DCL routines??  One example
>:    might be evaluating a SYMBOL instead of checking SYMBOL .EQS. "TRUE" - 
>:    the former should be faster, yes??
       :
>The only really powerfull optimization I bother using is to move the
>traditional programmer's prolog to the epilog, with an unconditional $EXIT in
>front of it.  That saves DCL from reading and parsing all those comments
>(yes, DCL parses comments, ever try to comment out f$verify?).  Even a $GOTO

I wrote a command procedure (RIP.COM) a number of years ago that does speed
up DCL procedures somewhat, but it's only really noticable on very large
procedures (say, over 500 lines) or on very slow machines (Microvax 2).  It
does a bunch of things, like eliminating comments, stripping out unneeded
spaces, etc.  It also allows easier debugging of DCL procedures by allowing
you to include specially commented lines that are either included or
stripped, depending on how you run the processing procedure.

The procedure is included below.  Use it in good health.  No guarantees,
warantees, etc. either stated, implied or even suspected.  Break it and you
own all the parts.  If anything goes wrong, I never heard of it.  If it
saves your life some day and you want to show gratitude, either do something
nice for someone sometime, or send large quantities of small bills and I'll
take care of spreading the good cheer.  Clear?  OK.

            ----------------begin included file----------------

$!======================================================================
$!
$!  RIP.COM -
$!
$!    Remove comments from command procedures to speed execution, and 
$!    allow the decommenting of "debug" lines if desired (similar to 
$!    Fortran's "D-LINES" capability).
$!
$! This procedure is invoked by the following command:
$!
$!	$@RIP <filename> [<switches>]
$!
$!  The operation is:
$!
$!	1. Open the current version of <filename>. If no <filename> is given,
$!	   abort with an error. If <filename> has no extension assume .SRC.
$!	   
$!	2. Open a temp file called XXX.XXX  
$!	   
$!	3. For each line in <filename>: 
$!	   
$!	     a. If the line is not a comment ('$!') or a debug line ('$!D!')
$!	        then compress the spaces in it (except for quoted strings), 
$!		strip any trailing comments, and write the line to the 
$!		temp file.
$!
$!	     b. If the line is a comment, or it is a debug line and <DEBUG> was
$!	        not specified, throw it away and get the next line.
$!
$!	     c. If the line is a debug line and <DEBUG> was specified, then
$!	        remove the '!D!' and write the line to the temp file.
$!	   
$!	4. RENAME the temp file back to the original file name, but use the
$!	   extension ".COM" no matter what the input file extension was.
$!	   NOTE: if the original extension was .COM then rename the original
$!	         file to have an extension of .SRC
$!	   
$!	5. Done.
$!------------------------------------------------------------------------------
$!
$!  The switches are separated by commas (NO BLANKS!). Possibilities are:
$!
$!	DEBUG - Causes debug lines to be output as executable statements.
$!		Default is to treat debug lines as comments.
$!
$!	BATCH - Causes suppression of information messages.
$!
$!***************************************************************************
$!  Check for correct params and for switches.
$!  If the filename has no extension then force it to .SRC
$!---------------------------------------------------------------------------
$  oldverify = f$verify(0)
$!D! set verify
$!
$  SAY = "WRITE SYS$OUTPUT "
$!
$  if (p1 .eqs. "")  	 then goto NO_FILE_ABORT
$  if (p1 .eqs. "DEBUG") then goto NO_FILE_ABORT
$  FILENAME	= p1
$  FILENOEXT	= f$parse(FILENAME,,,"NAME",)
$  FILEORIGEXT	= f$parse(FILENAME,,,"TYPE",)
$  if (FILEORIGEXT .nes. "") then goto FILE_NAME_OK
$  FILEORIGEXT :=  SRC
$  FILENAME    :=  'FILENOEXT'.SRC
$!
$FILE_NAME_OK:
$  SWITCHES	= p2			! optional parameter
$  SW_LEN	= f$length(SWITCHES)
$  DEBUG := ""
$  BATCH := ""
$  if (SW_LEN .eq. 0) then goto STARTUP
$  if (f$locate("DEBUG",SWITCHES) .lt. SW_LEN) then DEBUG := "DEBUG"
$  if (f$locate("BATCH",SWITCHES) .lt. SW_LEN) then BATCH := "BATCH"
$!
$STARTUP:
$!------------------------------------------------------------------------------
$! Define some symbols
$!------------------------------------------------------------------------------
$  if (BATCH .eqs. "BATCH") then SAY := "!"
$!------------------------------------------------------------------------------
$  say " "
$  say "Starting ''DEBUG' run..."
$!---------------------------------------------------------------------------
$!  OPEN all files
$!---------------------------------------------------------------------------
$  OPFILE = FILENAME
$  open/read/error=OPENFILE_ERR  INFILE  'FILENAME'
$  OPFILE = "XXX.XXX"
$  open/write/error=OPENFILE_ERR TEMP	 'OPFILE'
$!
$!---------------------------------------------------------------------------
$!  Start processing infile
$!---------------------------------------------------------------------------
$MAINLOOP:
$!
$  read/error=READFILE_ERR/end=FOUND_EOF INFILE  INLINE
$  if (f$extract(0,2,INLINE) .nes. "$!") then goto OUT_LINE
$  if (f$extract(0,4,INLINE) .eqs. "$!D!") .and. -
      (DEBUG .eqs. "DEBUG") then goto OUT_DEBUG_LINE
$  GOTO MAINLOOP
$!
$OUT_DEBUG_LINE:
$  INLINE = f$extract(4,f$length(INLINE),INLINE)
$OUT_LINE:
$!
$!  Compress the blanks, remove trailing comments, etc. before writing it out
$!
$  gosub STRIPPER
$  write TEMP INLINE
$  goto MAINLOOP
$!
$STRIPPER:
$  INLINE = f$edit(INLINE, "COMPRESS,UNCOMMENT,TRIM")
$  POS = 0
$  OLEN = f$length(INLINE)
$  NSTR = ""
$  INQUOTE = "NO"
$!
$STRIPLOOP:
$  if (POS .ge. OLEN) then goto DONE_STRIP
$  NEXCHAR = f$extract(POS,1,INLINE)
$  POS = POS + 1
$  if ((NEXCHAR .eqs. " ") .and. (INQUOTE)) .or. -
      ((NEXCHAR .nes. " ") .and. (NEXCHAR .nes. """"))
$   then
$     NSTR = NSTR + NEXCHAR
$   else
$     if (NEXCHAR .eqs. """")
$      then
$	 if (f$extract(POS,1,INLINE) .eqs. """")	! check for ""
$	  then
$	    POS = POS + 1
$	    NEXCHAR = """"""
$	  else
$	    INQUOTE = .not. INQUOTE
$	 endif
$        NSTR = NSTR + NEXCHAR
$      else
$	 if (NEXCHAR .eqs. " ")
$	  then            		! check for un-needed " ", not in quotes
$	    prevchar = f$extract(POS-2,1,INLINE)
$	    if (POS .eq. 2) .and. (prevchar .eqs. "$") then goto SKIP_SPACE
$!
$	    if (prevchar .eqs. "(") .or. -	!no spaces after...
	       (prevchar .eqs. ")") .or. -
	       (prevchar .eqs. "=") .or. -
	       (prevchar .eqs. ",") .or. -
	       (prevchar .eqs. "+") .or. -
	       (prevchar .eqs. "-") .or. -
	       (prevchar .eqs. "*") .or. -
	       (prevchar .eqs. "/") .or. -
	       (prevchar .eqs. ".") then goto SKIP_SPACE
$!
$	    next1char = f$extract(POS,1,INLINE)
$	    next2char = f$extract(POS,2,INLINE)
$	    if (next2char .eqs. ":=") .or. -   !no spaces before...
	       (next2char .eqs. "==") .or. -
	       (next1char .eqs. "(")  .or. -	
	       (next1char .eqs. ")")  .or. -
	       (next1char .eqs. "=")  .or. -
	       (next1char .eqs. ".")  .or. -
	       (next1char .eqs. ",")  .or. -
	       (next1char .eqs. "+")  .or. -
	       (next1char .eqs. "-")  .or. -
	       (next1char .eqs. "*")  .or. -
	       (next1char .eqs. "/")  .or. -
	       (next1char .eqs. ":")  then goto SKIP_SPACE
$!
$	    NSTR = NSTR + " "	!need to keep it for seperation
$!
$SKIP_SPACE:
$	 endif
$     endif
$  endif
$  goto STRIPLOOP
$!
$DONE_STRIP:
$  INLINE = NSTR
$  RETURN
$!
$!---------------------------------------------------------------------------
$!  Now close the files, and rename the temp file to the input file name, but
$!    always make the extension .COM. If the original extension was .COM then
$!    rename the original to .SRC
$!---------------------------------------------------------------------------
$FOUND_EOF:
$  close/nolog INFILE
$  close/nolog TEMP
$  if (FILEORIGEXT .nes. "COM") then goto FEOF_1
$  rename 'FILENAME' 'FILENOEXT'.SRC
$  say "Original extension was '.COM' so original renamed to ''FILENOEXT'.SRC"
$!
$FEOF_1:
$  rename XXX.XXX  'FILENOEXT'.COM
$  say "De-commented version name is ''FILENOEXT'.COM"
$  say "DECOMM.COM, Done."
$  goto EXIT_EXIT
$!---------------------------------------------------------------------------
$!***************************************************************************
$!
$!  ERROR ROUTINES
$!___________________________________________________________________________
$!
$NO_FILE_ABORT:
$  say "No input file specified."
$  goto EXIT_EXIT
$!
$OPENFILE_ERR:
$  say "ERROR OPENING FILE: ''OPFILE'"
$  goto EXIT_EXIT
$!
$READFILE_ERR:
$  say "ERROR READING FILE: ''FILENAME'"
$  goto EXIT_EXIT
$!
$!***************************************************************************
$!
$EXIT_EXIT:
$  foo = f$verify(oldverify)
$  Exit
             ----------------end included file----------------

 -- Mike "it's old, so keep any snide comments to yourself, OK?" Bartman --

==============================================================================
| I didn't really say all the things that I said.  You probably didn't read  |
| what you thought you read.  Statistics show that this whole thing is more  |
| than likely just a hideous misunderstanding.				     |
==============================================================================

==============================================================================
Never argue with a woman when she's tired, or rested.
------------------------------------------------------------------------------



