From:	SMTP%"carl@SOL1.GPS.CALTECH.EDU"  9-JUN-1994 09:28:28.75
To:	EVERHART
CC:	
Subj:	Re: version_limit of a file

From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
X-Newsgroups: comp.os.vms
Subject: Re: version_limit of a file
Date: 7 Jun 1994 22:01:10 GMT
Organization: HST Wide Field/Planetary Camera
Lines: 137
Distribution: world
Message-Id: <2t2qn7$qjp@gap.cco.caltech.edu>
Reply-To: carl@SOL1.GPS.CALTECH.EDU
Nntp-Posting-Host: sol1.gps.caltech.edu
To: Info-VAX@CRVAX.SRI.COM
X-Gateway-Source-Info: USENET

In article <1994Jun6.195520.17420@wuerl.wustl.edu>, allen@wuerl.wustl.edu (Allen Rueter) writes:
=I do have a clue, and that was a clue, poor tho.
=The best? way to get the version limit, how about the following command file
=that takes a file spec for an argument.
=
=$ if f$locate( ";",p1) .eq. f$Len(p1) then p1 = p1+";"
=$ directory/full 'p1 /out=jnk.d
=$ search jnk.d version /out=jnk.s
=$ delete /nolog jnk.d;
=$ open j jnk.s/read
=$ read j line
=$ verlim = 0
=$ if f$locate("No version limit", line) .ne. f$Len(line)
=$  then write sys$output "no version limit"
=$    goto done
=$ endif
=$ o = f$locate("Version limit:", line)
=$ if o .ne. f$len(line)
=$  then verlim = f$extract( o+15, 5, line)
=$    write sys$output "Version limit is ", verlim
=$  else write sys$output "Hmmm, problem finding version limit."
=$ endif
=$done:
=$ close j
=$ delete/nolog jnk.s;
=$ exit

Well, let's see now.  This procedure uses four image activations (DIRECTORY,
SEARCH, DELETE, and DELETE [you could cut that down to three by deleting both
files with one delete command]).  If you're willing to have an image activation
in there, then you might as well use a single image that gets the information
and doesn't use any temporary files.  For example:

#include iodef
#include fibdef
#include ssdef
#include rms
#include descrip
long stat;
#define ckstat(x) if(((stat = x) & 7) != 1) SYS$EXIT(stat)

main(int nargs, char **args)
{	struct FAB my_fab;
	struct NAM my_nam;
	struct fibdef my_fib;
	unsigned long i;
	char esa[255], rsa[255];
	struct
	{	unsigned long count, address; }
	fibdsc;
	char buffer[6];
	$DESCRIPTOR(symval, buffer);
	$DESCRIPTOR(devnam, "");
	$DESCRIPTOR(filnam, "");
	$DESCRIPTOR(symnam, "");
	unsigned short chan, iosb[4];

	if (nargs != 3)
	{	puts("Usage:  verlimit filename symbol");
		SYS$EXIT(SS$_INSFARG);
	}
	my_fab = cc$rms_fab;
	my_fab.fab$l_fna = *++args;
	my_fab.fab$b_fns = strlen(*args);
	my_fab.fab$b_fac = 0;
	my_fab.fab$b_shr = FAB$M_UPI;
	my_fab.fab$l_nam = &my_nam;
	my_nam = cc$rms_nam;
	my_nam.nam$b_ess = 255;
	my_nam.nam$l_esa = esa;
	my_nam.nam$b_rss = 255;
	my_nam.nam$l_rsa = rsa;
	ckstat(SYS$PARSE(&my_fab));
	ckstat(SYS$SEARCH(&my_fab));
	devnam.dsc$w_length = my_nam.nam$t_dvi[0];
	devnam.dsc$a_pointer = my_nam.nam$t_dvi + 1;
	for(i = 0; i < sizeof(my_fib); ++i)
		*(((char *) &my_fib) + i) = 0;
	my_fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NOTRUNC | FIB$M_PRSRV_ATR |
		FIB$M_NOLOCK | FIB$M_NORECORD;
	for(i = 0; i < 3; ++i)
		my_fib.fib$r_did_overlay.fib$w_did[i] = my_nam.nam$w_did[i];
	fibdsc.count = sizeof(my_fib);
	fibdsc.address = &my_fib;
	filnam.dsc$a_pointer = my_nam.nam$l_name;
	filnam.dsc$w_length = my_nam.nam$b_name + my_nam.nam$b_type +
		my_nam.nam$b_ver;
	ckstat(SYS$ASSIGN(&devnam, &chan, 0, 0));
	ckstat(SYS$QIOW(0, chan, IO$_ACCESS, iosb, 0, 0,
		&fibdsc, &filnam, 0, 0, 0, 0));
	ckstat(iosb[0]);
	SYS$QIOW(0, chan, IO$_DEACCESS, iosb, 0, 0, &fibdsc, 0, 0, 0,
		&0, 0);
	symnam.dsc$a_pointer = *++args;
	symnam.dsc$w_length = strlen(*args);
	sprintf(buffer, "%d", my_fib.fib$w_verlimit);
	symval.dsc$w_length = strlen(buffer);
	SYS$EXIT(LIB$SET_SYMBOL(&symnam, &symval));	
}

The program assigns the version limit of the file passed as the first argument
to the symbol passed as the second argument.  E.g.: 

$	DIRE/FULL VERLIMIT.C;

Directory DISK$USERDISK:[CARL.PROGS]

VERLIMIT.C;11                 File ID:  (15935,3,0)        
Size:            4/6          Owner:    [WFPC,CARL]
Created:  1994-06-07 13:50:42.32
Revised:  1994-06-07 13:50:42.57 (1)
Expires:  1994-09-05 13:51:43.54
Backup:    <No backup recorded>
File organization:  Sequential
File attributes:    Allocation: 6, Extend: 0, Global buffer count: 0,
		    Version limit: 10
Record format:      Variable length, maximum 75 bytes
Record attributes:  Carriage return carriage control
RMS attributes:     None
Journaling enabled: None
File protection:    System:RWED, Owner:RWED, Group:RE, World:RE
Access Cntrl List:  None

Total of 1 file, 4/6 blocks.
$	VERLIMIT :== $DISK$USERDISK:[CARL.PROGS]VERLIMIT
$	FUBAR :=
$	VERLIMIT VERLIMIT.C FUBAR
$	SHO SYM FUBAR
  FUBAR = "10"
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.

