USE statement

Maclary, David dmaclary@wellmanage.com
Wed, 7 Oct 1998 09:21:01 -0400


Well, I finally got back to working on this.  We last left off with...

> USEQUIZ.CMD
> ===========
> parm sourcefile
> continue
> purge quizuse,temp
> /listq $use !sourcefile > quizuse   {list sourcefile, expanding referenced
> files}
> /text quizuse
> /deleteq "&dB"   {delete lines with inverse hilite}
> /deleteq "~use@"(pattern) {delete redundant use file references}
> /keep,yes
> quiz
> 
This seemed okay at first, but /listq $use !sourcefile > quizuse didn't
work. The ">" is a
CI thing, and the "/" forces the line to be interpreted by QEdit.  When I
mixed the two, it
got ugly.

Then, it got worse. I hadn't taken into account USE files that are generated
on-the-fly...oops!
When the above approach trys to expand a USE file that does not exists, the
script fails.
Back to the drawing board...

I ended up creating a few command files, with a mix of MPE and QEdit to
simulate how Quiz
handles USEs, without the "it has to be it's own statement" limitation.
Also, I think this also
does away with the limit of 20 levels of nested USEs.

----------------------------------------------------------------------------
-------------------------------------------------------
QEXPAND command file

PARM sourcefile,DEBUG=FALSE
MKFILE FILE=qedin1 ,FILEPARMS=TEMP;REC=-80,,F,ASCII;DISC=100000
MKFILE FILE=qedin2 ,FILEPARMS=TEMP;REC=-80,,F,ASCII;DISC=100000
MKFILE FILE=qedout1,FILEPARMS=TEMP;REC=-80,,F,ASCII;DISC=100000
MKFILE FILE=quse   ,FILEPARMS=TEMP;REC=-80,,F,ASCII;DISC=100000
PURGE qeditscr,TEMP > $NULL
FILE LPA=!qedin2,OLDTEMP;DEV=disc
FILE LPB=!quse  ,OLDTEMP;DEV=disc
ECHO LQ $LPB !sourcefile                   >> !qedin1
ECHO T !quse                               >> !qedin1
ECHO QEXPAND2                              >> !qedin1
ECHO K,Y                                   >> !qedin1
ECHO E                                     >> !qedin1
CONTINUE
RUN QEDIT.PUB.ROBELLE;PARM=128;INFO="USE !qedin1" > !qedout1
IF cierror <> 900 OR !debug THEN
   PRINT !qedout1
ELSE
   FILE quse = !quse
ENDIF
PURGE !qedin1 ,TEMP > $NULL
PURGE !qedin2 ,TEMP > $NULL
PURGE !qedout1,TEMP > $NULL

Note: This uses another command file called MKFILE, which creates a unique,
randomly
named temporary file, and returns the name of the created file in a variable
passed with the
FILE parameter.

----------------------------------------------------------------------------
-------------------------------------------------------
QEXPAND2 command file

LISTFTEMP tmp@,2
/SET WINDOW (UP)
SETJCW cierror = 0
SETVAR FIRSTNEXT "FIRST"
#
# Expand use statements.
#
WHILE cierror = 0 DO
   CONTINUE
   /FIND "~use @"(UPSHIFT PATTERN) !FIRSTNEXT
   IF cierror = 0 THEN
      /LQ $LPA *
      INPUT rec < !qedin2
      ECHO
      ECHO PROCESSING = !rec
      #
      # This use has already been expanded.
      #
      IF UPS(WORD(rec,,1)) = "USE"   AND &
         UPS(WORD(rec,,2)) = "*QUSE" THEN
         ECHO OK      = !rec
         SETVAR FIRSTNEXT ""
      ELSE
         #
         # A permanent use file (with the group name specified)
         # exists. Expand it now.
         #
         FILE quseperm = ![WORD(rec,,2)],OLD
         IF POS('.',WORD(rec,,2)) > 0 AND &
            FINFO("*quseperm", "EXISTS") THEN
            ECHO EXISTS  = !rec
            /C 1 ";" *
            /AQ * ";-----Begin ![UPS(WORD(rec,,2))]"
            /AQ * = ![WORD(rec,,2)]
            /AQ * ";-----End ![UPS(WORD(rec,,2))]"
            LISTFTEMP TMP@,2
         ELSE
            #
            # Expand the use file at runtime.
            #
            ECHO MISSING = !rec
            /C 1 ";" *
            /A * ":QEXPAND ![WORD(rec,,2)]"
            /A * "USE *quse ; Use expanded ![WORD(rec,,2)]"
            LISTFTEMP TMP@,2
         ENDIF
         SETVAR FIRSTNEXT "FIRST"
      ENDIF
   ENDIF
ENDWHILE

Note: This script immediately expands USE files if they are permanent and
have the MPE
group name specified. Otherwise, they are expanded later, when the code is
executed.

----------------------------------------------------------------------------
-------------------------------------------------------

To make all of this work is a simple matter of QEXPANDing a file and doing a
USE *quse.

Regards,
David Maclary

> ----------
> From: 	Hans Hendriks[SMTP:hans@robelle.com]
> Sent: 	Tuesday, June 23, 1998 3:08 PM
> To: 	Maclary, David; powerh-l@lists.swau.edu
> Subject: 	RE: USE statement
> 
> David Maclary ( dmaclary@wellmanage.com ) asks:
> 
> > > The USE statement in PowerHouse is limited in that it is it's own
> > > statement, and therefore can not be used within other statements, like
> > > report groups, etc.  What this means is that code can not be
> > written once
> > > and reused "anywhere", which reduces code reusability and increases
> > > program maintenance.
> > >
> > > For instance, in Quiz, I can...
> > >
> > > USE FILE.GROUP
> > >      ITEM5 &
> > >      ITEM6
> > >
> > > Where FILE.GROUP contains...
> > >
> > > REPORT &
> > >     ITEM1 &
> > >     ITEM2 &
> > >
> > > But, what would really be useful, is to be able to...
> > >
> > > REPORT &
> > >     ITEM1 &
> > >     ITEM2 &
> > > USE FILE2.GROUP2
> > >     ITEM5 &
> > >     ITEM6
> > >
> > > where FILE2.GROUP2 contains code that I want to reuse in a number of
> > > places, and the code before and after the USE changes.
> > >
> > > One workaround that I'm experimenting with is to use VESOFT's STREAMX
> > > program, which does not have the PowerHouse limitation.  The problem
> is
> > > that I'd have to replace all PowerHouse USEs with STREAMX USEs and do
> a
> > > prepass on all reports with STREAMX before running them.  Here is the
> > > command file so far...
> > >
> > > PARM STRMXIN,STRMXOUT
> > > FILE STRMFILE=!STRMXIN
> > > FILE STRMSAVE=!STRMXOUT;REC=-80,,F,ASCII;DISC=999999
> > > IF FINFO("!STRMXOUT","EXISTS") THEN
> > >    PURGE !STRMXOUT
> > > ENDIF
> > > ERRCLEAR
> > > RUN STREAMX.PUB.VESOFT;PARM=%441 > STRMXOUT
> > > IF HPCIERR <> 0 THEN
> > >    PRINT STRMXOUT;PAGE=0
> > > ELSE
> > >    PRINT !STRMXOUT
> > > ENDIF
> > > RESET STRMFILE
> > > RESET STRMSAVE
> > >
> > > The input file would look like...
> > >
> > > REPORT &
> > >     ITEM1 &
> > >     ITEM2 &
> > > ::USE FILE2.GROUP2
> > >     ITEM5 &
> > >     ITEM6
> > >
> > > Has anyone else come up with workarounds to this problem?  If
> > so, I'd like
> > > to hear them !!!
> 
> Our <plug> Qedit </plug> editor has a feature for listing "included" files
> that you could "use" :-)
> 
> Qedit's LIST command accepts a "$use" option, which will search any use
> files referenced by a source file when listing strings or line ranges. (It
> also has a "$include" option for COBOL include files). For example, lets
> say
> you have 3 use files:
> 
> USE1
> -------
>   Here is the first line of the program
>   here is another line
>   use use2
>   second last line of use1
>   last line, all done
> 
> USE2
> -------
>   *****************************
>   here is a line in USE2
>   ...and another line in USE2
>   use use3
>   Last Line in USE2
>   ******************************
> 
> USE3
> -------
>   ++++++++++USE3!!!++++++++++++++++
>   here is a second-level nested use file
>   ++++++++++++++++++++++++++++++++
> 
> ... when you do a "listq $use USE1", you'll see: (My comments at right)
> 
>   Here is the first line of the program       <<<< first line of USE1
>   here is another line
>   use use2                                     <<<< reference to USE2
>   USE use2                                    <<<< Inverse highlighted
>   *****************************          <<<< First line of USE2
>   here is a line in USE2
>   ...and another line in USE2
>   use use3                                      <<<< Reference to USE3
>   USE use3                                     <<<< Inverse highlighted
>   ++++++++++USE3!!!+++++++++++++++  <<<< first line of USE3
>    here is a second-level nested use file
>   ++++++++++++++++++++++++++++++++
>   end $include                                 <<<< Inverse highlighted
> (end
> of USE3)
>   Last Line in USE2
>   ******************************
>   end $include                                 <<<< inverse highlighted
> (end
> of USE2)
>   second last line of use1
>   last line, all done
> 
> It's quite easy to package this into a command file as follows:
> 
> USEQUIZ.CMD
> ===========
> parm sourcefile
> continue
> purge quizuse,temp
> /listq $use !sourcefile > quizuse   {list sourcefile, expanding referenced
> files}
> /text quizuse
> /deleteq "&dB"   {delete lines with inverse hilite}
> /deleteq "~use@"(pattern) {delete redundant use file references}
> /keep,yes
> quiz
> 
> Advantages over STREAMX?:
> - No editing required for existing use file references
> - handles "nested" use files.
> 
> Hope this makes sense .....
> 
> /Hans
> |----------------------------------------------------------------------
> | Hans Hendriks       Robelle Consulting
> | http://www.robelle.com/~hans
> | hans@robelle.com    personal:hans@cheerful.com
> 
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> =
> Subscribe: "subscribe powerh-l" in message body to
> majordomo@lists.swau.edu
> Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
> powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
> This list is closed, thus to post to the list, you must be a subscriber.
> 
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
This list is closed, thus to post to the list, you must be a subscriber.