HP3000-L Archives

July 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:
Tue, 9 Jul 1996 19:05:25 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (105 lines)
On Jul 9, 12:32pm, Paul H. Christidis wrote:
> Subject: Re: Command file questions
> <<===
> 1. Is there a way that an executing MPE/iX command file can determine its
> name (file-name, group, account)?
> ===>>
>
> Yes. The system variable 'HPFILE' is set to the name of the currently
> executing UDC or Command file.
 
Correct.  And for pre 5.0 systems it is not as easy.  If your command file
is always invoked from the CI (and not from within another command file or
UDC) then you can extract the name used to invoke it by dereferencing the
history stack, "!-1".  E.g.:
 
---------
  PARM a,b,c
  SETVAR previous_cmd "!-1"+" "
  SETVAR myname ups(lft(previous_cmd,pos(" ",previous_cmd)-1))
  IF myname = "XEQ" then
     COMMENT need to extract the next token (= real script name)
     SETVAR previous_cmd rht(previous_cmd, len(previous_cmd)-4)
     SETVAR myname ups(lft(previous_cmd,pos(" ",previous_cmd)-1))
  ENDIF
  COMMENT "myname" may be qualified or unqualified.
  COMMENT Doesn't work where a space isn't the name delimiter, e.g.,
:foo$oldpass
  COMMENT HPFILE var is a lot easier!
---------
 
On 5.5 this kind of parsing is easier.  Here is the same command file
using some of the new 5.5 word() function:
 
------------
PARM a,b,c
SETVAR myname ups(word("!-1"))
IF myname = "XEQ" then
   # need to extract the next token (= real script name)
   SETVAR myname ups(word("!-1",,2))
ENDIF
# This *does* handle cases where space is not the name delimiter
-----------
 
>
> <<===
> 2. Can I perform I/O on a file within a loop and read successive records? I
> tried a WHILE loop but I keep reading the same record:
>
>     SETVAR COUNTER 1
>     WHILE COUNTER < FINFO ("file","EOF) DO
>         INPUT variable<file
>         do something else
>         SETVAR COUNTER COUNTER + 1
>     ENDWHILE
 
Yes this just reads the 1st record over and over until it has been read EOF
times!  The INPUT command does not know it is in a WHILE loop.  I/O
redirection (< or > or >> filename) just opens filename as $stdin or $stdlist
then closes the file before the CI fetches the next command. To iterate I/O
redirection on a series of commands or to read sequentially from a file
the block of commands itself needs to be redirected (as shown below)
 
>
> ===>>
>
> Try the following
>         file a;rec=![finfo("file","recsize")],,f,ascii;msg
>         print file >*a
>         while finfo("*a","eof") > 0 do
>            input variable < *a
>            do something
>         endwhile
 
Using a MSG file is conceptually nice but performs much slower than
serially reading a non-MSG file.  I've done measurements that show
sequential CI reads of the same data 1) in a MSG file vs. 2) in a flat ascii
file to be up to 88% faster using the flat ascii file.  Here is an easy
way to do this:
 
-------
parm file_to_read, entry=main
if "!entry" = "main" then
   xeq !HPFILE !file_to_read, entry=readit <!file_to_read
   # (call myself with the "readit" entry and input directed to "file_to_read")
   #  cleanup...
   return
   # (leave the command file)
 
elseif "!entry" = "readit" then
   #  Input redirected from "file_to_read" parameter
   setvar eof finfo(HPSTDIN,"eof")
   setvar i 0
   while setvar(i,i+1) <= eof do
      setvar record input()
      #  process record...
   endwhile
   return
   # (return to myself in the "main" entry code)
endif
 
regards,
Jeff Vance, CSY
 
--

ATOM RSS1 RSS2