HP3000-L Archives

November 1996, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jeff Vance <[log in to unmask]>
Reply To:
Jeff Vance <[log in to unmask]>
Date:
Thu, 7 Nov 1996 10:35:08 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (71 lines)
On Nov 7, 11:57am, Thomas Harmon wrote:
> Subject: Re: FINFO - How can I determine if a file is in use?
snip...
> I call the CMD file CHACTIVE for CHeck ACTIVE and invoke it as follows:
>      !CHACTIVE @F@
>      !IF INUSE = 1
>      !    TELLOP *JPAYCALC - FILES IN USE CANNOT CREATE BEFORE TAPE
>      !    TELLOP *JPAYCALC - CORRECT AND STREAM JPAYCALC AGAIN
>      !    SJ .BPP
>      !    EOJ

Note that wildcarding is used in the above example, so the INUSE var indicates
if any matching file is in use.

> Here is the CMD file:
> parm File_Name="None",Entry="Main",Flen=0    (1)
> option nolist
> if "!Entry"="Main"
>     LISTF !File_Name,2>temp                  (2)
>     setvar templen finfo("temp",19)          (3)
>     chactive Entry="Check" Flen=templen<temp
>     return
> endif
> if "!Entry"="Check"
>     setvar tempctr 0
>     setvar inuse 0
>     while tempctr<!flen                      (4)
>         setvar temprec " "
>         input temprec
>         if len("!temprec") > 20
>             if str("!temprec",9,1)="*"
>                 setvar inuse 1
>             endif
>         endif
>         setvar tempctr tempctr + 1
>     endwhile
>     deletevar temprec                         (5)
>     deletevar tempctr
>     deletevar templen
>     return
> endif

Here are some minor suggestions for improving this good script that may
help Thomas and others later on...

(1) "none" is a legal MPE filename, maybe the File parm should be
required (leave off the ="none" part), or maybe the default should be '@'

(2) I know everyone uses LISTF, but LISTFILE is slightly faster, supports
POSIX names and has more features, like selection equations.
I would also put a CONTINUE before the LISTF and check CIERROR or HPCIERR
after the LISTF - make sure LISTF found at least 1 file.

(3) I would use finfo("temp","eof") rather than 19 -- self documenting.
And you don't really need to create the tmplen var, you can re-invoke the
script as:
   xeq chactive Entry="Check" Flen=![finfo("temp","eof")] <temp

(4) As long as you define INUSE as a boolean rather than a counter you
can exit the while loop after the first inuse file., eg:
   while inuse = 0 and setvar(tempctr,tempctr+1) < flen do ...

(5) You can combine all the deletevars together:
        deletevar temprec, tempctr, templen


Thanks for the example!
Jeff ("maybe I've been working on the CI too long??") Vance, CSY

--

ATOM RSS1 RSS2