From: bruce@ais.com (Bruce C. Wright)
Newsgroups: comp.os.vms
Subject: Re: WANTED: VMS calculator program
Date: 27 Jan 93 11:20:51 GMT
Organization: Applied Information Systems, Chapel Hill, NC

In article <20301.2b5ad225@ul.ie>, 9118187@ul.ie writes:
> I'm looking for a VMS calculator program. Does anyone know if such a program
> exists?

If you want one that runs under DECwindows, there is a (fairly weak)
calculator that comes with DECwindows.

For many purposes (integer arithmetic, conversion between decimal,
unsigned decimal, hex, etc), I find a simple DCL command file works
pretty well.  It doesn't do floating point or fractional arithmetic,
if that's important to you (you don't say what you want it for).

------------------------- cut here -----------------------------
$ ! DC.COM
$ !
$ ! Command file to implement a desk calculator on the VAX.
$ !
$ ! Usage:
$ !
$ !	dc :== @sys$login:dc
$ !
$ !	dc expression
$ !
$ ! The command file accepts all DCL numeric operators and lexical functions,
$ ! such as +, -, *, /, .and., and .or..  Hexadecimal numbers can be entered
$ ! by prefixing them with %x, eg %x100;  octal numbers can be entered by
$ ! prefixing them with %o.  A character can be evaluated as its internal
$ ! binary value by prefixing it with a #, eg #A, #"a", ##.  Note that
$ ! DCL requires lower-case letters to be enclosed in quotes if they are
$ ! not to be translated to upper case;  also any characters that are
$ ! special characters for DCL need to be enclosed in quotes, for example,
$ ! #"'" or #"""".
$ !
$ 	if p1 .nes. "" then goto skip
$ loop:	inquire/nopunctuation p1 "$_Expression:  "
$ 	if p1 .eqs. "" then goto loop
$ skip:	p := 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
$!
$! Convert #'s to f$cvui's so it's easier to convert characters to binary.
$! The offset variable is used to keep from rescanning characters we've
$! already converted to allow syntax like ##.  Also fixup the " character
$! so that it can be used as the argument of # as well.
$!
$	offset = 0
$ test:	i = offset + f$locate ("#", f$extract (offset, f$length(p)-offset, p))
$	if i .ge. f$length (p) then goto done
$	c = f$extract(i+1,1,p)
$	if c .eqs. """" then c = """"""
$	p = f$extract(0,i,p) + "f$cvui(0,8,""" + -
		c + """)" + f$extract(i+2,f$length(p),p)
$	offset = i + 14 + f$length (c)
$	goto test
$!
$ done:	write sys$output f$fao -
		("Hex = !XL Octal = !OL Decimal = !SL Unsigned = !UL", -
		'p','p','p','p')
------------------------- cut here -----------------------------

Equate a symbol to run the command file ($ dc :== @sys$login:dc)
and then you can type things like `$ dc 255 .and. 3' or whatever.
Its main virtues over just typing `$ write sys$output 255 .and. 3'
are brevity and the conversion to hex and octal;  but it makes a
reasonable quick calculator for many programming purposes.  You
can enter hex numbers by typing things like `$ dc %x100+%x200';
you can even get the binary value of a character by using the
expression `$ dc #A';  lower case with `$ dc #"a"'.  (The expression
`$ dc f$cvui(0,8,"""A""")' also works, of course, but it's ugly
and a lot of typing).

One minor `bug':  because DCL can't handle more than 8 parameters,
you may not be able to type spaces between all your numbers and
operators, but may need to concatenate some or all of them together
into one parameter.

There are numerous fancier programs available, but for most of my
purposes this works well enough that I don't feel much need for them.

Bruce C. Wright