From:	SMTP%"vandenheuvel@eps.enet.dec.com"  9-JAN-1995 10:19:57.90
To:	EVERHART
CC:	
Subj:	Re: random record access from DCL?

From: vandenheuvel@eps.enet.dec.com (Hein RMS van den Heuvel)
X-Newsgroups: comp.os.vms
Subject: Re: random record access from DCL?
Date: 9 JAN 95 00:19:24
Organization: Digital Equipment Corporation
Lines: 63
Message-ID: <3eqi7u$gi4@jac.zko.dec.com>
NNTP-Posting-Host: EPSYS
To: Info-VAX@Mvb.Saic.Com
X-Gateway-Source-Info: USENET


In article <D22p2B.GFp@world.std.com>, jcomeau@world.std.com (John O Comeau) writes...
>Is there a way to trick DCL into random access of records from fixed-512-byte
>files? I tried I tried read/key=""/index=5 but it didn't like the null key.
>Any ideas? Thanks - John

Index=5 ! Wow. Why?

Anyway. Yes, can be done with some restrictions. As per RMS documentation
you'd need a ksz=4 (32 bit unsigned integer key) + rac=key for random access
to a fixed length sequential file. In DCL this is best done with 4 byte
character key. The 'trick' needed is to avoid DCL from interpreting the
bytes too early and then try to 'help' with substitution and such: Use &.
They solution then looks like:

    $x="1234"                     ! Allocate 4 byte string.
    $x[0,32]='record_number 	  ! Stuff binary value into 4 byte string
    $read/key=&x some_file record

I'll include a complete example where dcl random access is used to 
read random disk block from a moun/for device in order to patch up
a master directory file header that 'accidently' got hosed.

The catch is when the binary value in any byte looks a doublequote: "
If you _have_ to deal with that, you'll need to read the record before
that via key and then just read next your way to the record(s) with 
unacceptable key value. :-(. I'll

> 
>PS - In case anyone's wondering why - I'm writing a block device driver 
>for RSX that does block I/O over the ethernet to a container file on the
>VAX, and I want to get a Sniffer dialogue of a comparable VAX-VAX 
>transaction so I don't have to buy all the freaking Phase IV DECNet manuals,
>and I want to avoid relearning VAX Macro if I can - haven't used it in 3 
>years...

So, what's the big deal? Just use Fortran, C, Cobol, Basic or whatever
real language you have on the VAX other than DCL or Macro?

    $mount/for mess:	! mess = Logical name pointing to target device
    $open/read/write broken mess:
    $x="1234"
    $x[0,32]=1
    $read/key=&x broken home
    $ibmaplbn =  f$cvsi(24*8,32,home)
    $ibmapsize = f$cvsi(32*8,16,home)
    $x[0,32]= ibmaplbn + ibmapsize - 1 + 4     ! MFD = (4,4), VBN = LBN -1
    $read/key=&x broken mfd
    $filechar= f$cvsi(52*8,32,mfd)
    $fid = f$cvsi(8*8,32,mfd)
    $write sys$output f$fao("!XL !XL", fid, filechar) ! 0004004 00000080
    $mfd[52*8,32]= filechar + 8192		! FCH$M_DIRECTORY
    $check = f$cvsi(510*8,16,mfd)
    $mfd[510*8,16]= check + 8192
    $write/update/symbol broken mfd
    $close broken
    $dism/nounl mess
    $moun mess presto !  (label happened to be presto ;^)

Hope this helps,		+--------------------------------------+
Hein van den Heuvel, Digital.	| All opinions expressed are mine, and |
  "Makers of VMS and other	| may not reflect those of my employer |
   fine Operating Systems."	+--------------------------------------+
