From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 10-OCT-1990 00:54:14.15
To:	MRGATE::"ARISIA::EVERHART"
CC:	
Subj:	Re: DCL puzzle/competition...

Received:  by crdgw1.ge.com (5.57/GE 1.73)
	 id AA20803; Wed, 10 Oct 90 00:29:52 EDT
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Tue,  9 OCT 90 19:07:29 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA19972; Tue, 9 Oct 90 18:42:14 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 9 Oct 90 14:34:33 GMT
From: comp.vuw.ac.nz!gp.govt.nz!zl2tnm!don@uunet.uu.net  (Don Stokes)
Organization: Me?  Organised?
Subject: Re: DCL puzzle/competition...
Message-Id: <NNVsq2w163w@zl2tnm.gp.govt.nz>
References: <1990Oct7.211901.14409@elroy.jpl.nasa.gov>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

pjs@aristotle.JPL.NASA.gov (Peter Scott) writes:

> I haven't seen a follow-up to this post, and I haven't heard anything
> back from Nick, so I'm posting my answer.  Maybe there weren't
> enough entries...
> 
> 
> In article <9009061623.AA16686@ucbvax.Berkeley.EDU>  NICK@ncdlab.ulcc.ac.uk (
> > Hi, Light entertainment time !8-)
> > 
> > So you reckon you know DCL pretty well, huh? Here's a competition for those
> > who want to have a go. The winner's prize will be... having their name anno
> > as the winner!
> > 
> > Problem:
> > 
> > There is this binary record. In this record there is a VMS quadword time. U
> > ONLY DCL commands (no image invokation), display the time in VMS format. eg
> > 
> > 	$ Record[ 0, 32 ] = %x0CA87960	! Load 64 bit time into "record"
> > 	$ Record[ 32,32 ] = %x0094972C
> > 	...
> > 	$ Write SYS$OUTPUT "Date : '", ... ,"'"
> > 	$! should display: Date : '31-MAY-1991 23:59:59.99'
> > 
> > Fill in the missing DCL code! A general case solution is required for non-d
> > VMS time formats. No use of images external to DCL.EXE may be made, nor may
> > privilege be used (at all!).
> 
> 
> Piece of cake :-)
> 
> $ Record[ 0, 32 ] = %x0CA87960
> $ Record[ 32,32 ] = %x0094972C
> $ a = f$cvui(0,32,f$fao("!AD",4,%X'f$fao("!XL",Record)'+4))
> $ Write SYS$OUTPUT "Date : '", f$fao("!%D",'a') ,"'"
> 
> Self-explanatory.
> 
> 
> Well, okay, maybe a little explanation (after all, it did take me a few
> hours!).

Took *me* five minutes!  Nyah!  And did it in one line and one less
lexical!  8-)


$ record[0 ,32] = %x0CA87960
$ record[32,32] = %x0094972C
$ write SYS$OUTPUT "Date:'",f$fao("!%D",f$cvui(32,32,f$fao("!AD",8,record))),"'"

(Dang Nick and his long variable names -- I'd have liked to get it into
80 columns without losing the spaces either side of the ":" after the
"Date".... 8-)

Explanation:

                                             f$fao("!AD",8,record)

This returns a descriptor to the symbol "record" (or rather, a temporary
copy of the symbol).  "!AD" accepts a length by value, and an string by
reference.  What is passed by DCL into the $FAO system service is a longword
(8) by value, and a descriptor by reference.  The descriptor, contained in
a string is now passed by descriptor into...

                                f$cvui(32,32(                     )

... which extracts the longword address of the string from the bytes 4-7
of the descriptor to "record", passing it by value into...

                    f$fao("!%D",                                   )

... which is effectively passing the string by reference into the time
conversion function of $FAO.

Descriptors tend to wander around on the stack a bit -- pjs's response
is a tad suspect in that he relies on the value of "Record" to stay in
the same place for two lines of DCL.





> Anyone care to try writing DCL code to do the inverse conversion?  :-)

Well, that is a bit trickier.

I just did it by "trapping", mainly because I couldn't be bothered doing
the multiple precision arithmetic.  I did it simply by looping onr bit
at a time, from tyhe high bit to the low bit, using the above method to
convert the evolving quadword time into a time string, then used
f$cvtime to compare and see if any more bits need to be added -- if
adding a given bit takes the date over the target, then don't add the
bit.  63 passes of the loop (less actually) later, you've got your
answer, but it aint fast.



Now for a real challenge.  Given symbol D, which contains a directory
spec (eg device:[dir.subdir]), write an expression which returns in
symbol F the name of the directory file (eg device:[dir]subdir.dir;), in
less than 80 columns, including the "$ F=".  Abbreviated lexicals are
allowed.  It must handle device:[dir] -> device:[000000]dir.DIR.

A lesser challenge is a word count, ie given a string containing a
number of words, separated by arbitrary amopunts of whitespace, count
the number of words in the string.  One line again.  No abbreviations
this time (unless you want it to follow a full WRITE SYS$OUTPUT).

I occasionally admit to using this kind of rubbish in production code.
It's called job security 8-).



Don Stokes, ZL2TNM  /  /                            Home: don@zl2tnm.gp.govt.nz
Systems Programmer /GP/ Government Printing Office  Work:        don@gp.govt.nz
__________________/  /__Wellington, New Zealand_____or:_PSI%(5301)47000028::DON

