home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 22246 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  3.6 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!elroy.jpl.nasa.gov!sdd.hp.com!swrinde!gatech!concert!ais.com!bruce
  2. From: bruce@ais.com (Bruce C. Wright)
  3. Newsgroups: comp.os.vms
  4. Subject: Re: WANTED: VMS calculator program
  5. Message-ID: <1993Jan27.112051.5966@ais.com>
  6. Date: 27 Jan 93 11:20:51 GMT
  7. References: <20301.2b5ad225@ul.ie>
  8. Organization: Applied Information Systems, Chapel Hill, NC
  9. Lines: 78
  10.  
  11. In article <20301.2b5ad225@ul.ie>, 9118187@ul.ie writes:
  12. > I'm looking for a VMS calculator program. Does anyone know if such a program
  13. > exists?
  14.  
  15. If you want one that runs under DECwindows, there is a (fairly weak)
  16. calculator that comes with DECwindows.
  17.  
  18. For many purposes (integer arithmetic, conversion between decimal,
  19. unsigned decimal, hex, etc), I find a simple DCL command file works
  20. pretty well.  It doesn't do floating point or fractional arithmetic,
  21. if that's important to you (you don't say what you want it for).
  22.  
  23. ------------------------- cut here -----------------------------
  24. $ ! DC.COM
  25. $ !
  26. $ ! Command file to implement a desk calculator on the VAX.
  27. $ !
  28. $ ! Usage:
  29. $ !
  30. $ !    dc :== @sys$login:dc
  31. $ !
  32. $ !    dc expression
  33. $ !
  34. $ ! The command file accepts all DCL numeric operators and lexical functions,
  35. $ ! such as +, -, *, /, .and., and .or..  Hexadecimal numbers can be entered
  36. $ ! by prefixing them with %x, eg %x100;  octal numbers can be entered by
  37. $ ! prefixing them with %o.  A character can be evaluated as its internal
  38. $ ! binary value by prefixing it with a #, eg #A, #"a", ##.  Note that
  39. $ ! DCL requires lower-case letters to be enclosed in quotes if they are
  40. $ ! not to be translated to upper case;  also any characters that are
  41. $ ! special characters for DCL need to be enclosed in quotes, for example,
  42. $ ! #"'" or #"""".
  43. $ !
  44. $     if p1 .nes. "" then goto skip
  45. $ loop:    inquire/nopunctuation p1 "$_Expression:  "
  46. $     if p1 .eqs. "" then goto loop
  47. $ skip:    p := 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
  48. $!
  49. $! Convert #'s to f$cvui's so it's easier to convert characters to binary.
  50. $! The offset variable is used to keep from rescanning characters we've
  51. $! already converted to allow syntax like ##.  Also fixup the " character
  52. $! so that it can be used as the argument of # as well.
  53. $!
  54. $    offset = 0
  55. $ test:    i = offset + f$locate ("#", f$extract (offset, f$length(p)-offset, p))
  56. $    if i .ge. f$length (p) then goto done
  57. $    c = f$extract(i+1,1,p)
  58. $    if c .eqs. """" then c = """"""
  59. $    p = f$extract(0,i,p) + "f$cvui(0,8,""" + -
  60.         c + """)" + f$extract(i+2,f$length(p),p)
  61. $    offset = i + 14 + f$length (c)
  62. $    goto test
  63. $!
  64. $ done:    write sys$output f$fao -
  65.         ("Hex = !XL Octal = !OL Decimal = !SL Unsigned = !UL", -
  66.         'p','p','p','p')
  67. ------------------------- cut here -----------------------------
  68.  
  69. Equate a symbol to run the command file ($ dc :== @sys$login:dc)
  70. and then you can type things like `$ dc 255 .and. 3' or whatever.
  71. Its main virtues over just typing `$ write sys$output 255 .and. 3'
  72. are brevity and the conversion to hex and octal;  but it makes a
  73. reasonable quick calculator for many programming purposes.  You
  74. can enter hex numbers by typing things like `$ dc %x100+%x200';
  75. you can even get the binary value of a character by using the
  76. expression `$ dc #A';  lower case with `$ dc #"a"'.  (The expression
  77. `$ dc f$cvui(0,8,"""A""")' also works, of course, but it's ugly
  78. and a lot of typing).
  79.  
  80. One minor `bug':  because DCL can't handle more than 8 parameters,
  81. you may not be able to type spaces between all your numbers and
  82. operators, but may need to concatenate some or all of them together
  83. into one parameter.
  84.  
  85. There are numerous fancier programs available, but for most of my
  86. purposes this works well enough that I don't feel much need for them.
  87.  
  88. Bruce C. Wright
  89.