punits is a unit conversion program, complete with its own language used to define units. That just about sums it up. You can use the two units already defined, or you can write your own script. See below for details on writing your own units.
punits source code can be downloaded from http://sf.net/projects/punits/
The language used to define units is very limited. Currently, there are only 13 commands you can use in your script. The syntax is very simple, so defining units isn't very hard. The command character resides in the first column, then a space and the argument (if the command requires). The command characters are:
+- adds a constant (the argument) to the buffer
-- subtracts a constant (the argument) from the buffer
*- multiplies the buffer by a constant (the argument)
/- divides the buffer by a constant (the argument)
s- subtracts the buffer from a constant
d- divides a constant by the buffer
i- sets the buffer equal to the user's input
r- returns, with the answer in the buffer
f- specifies that the algorithm following is for converting forward -- see below.
b- specifies that the algorithm following is for converting backward -- see below.
n- specifies input type
o- specifies output type
c- simply ignores the rest of the line (a comment)
Let's see a real script:
The first line sets the input type to metres; the second sets the ouput type to inches. The third line begins the algorithm for forward (metres to inches). The fourth sets the buffer equal to the input. The fifth multiplies the buffer by 39.37. The sixth returns with the output stored in the buffer.
The seventh line begins the algorithm for backward (inches to metres). The eighth sets the buffer equal to the input. The ninth divides the buffer by 39.37. The tenth returns with the output in the buffer.
If you would like to contact me regarding punits, please feel free to email
Please include "punits" in the subject line, as I frequently delete masses
of emails from that mailbox. I can also be contacted over AOL Instant
Messenger; my screenname is
punits was written and is currently being developed by Matt Mullins. punits is distributed under the GPL General Public License.
punits is copyrighted © 2003 Matt Mullins, all rights reserved.