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 constantd
- divides a constant by the bufferi
- sets the buffer equal to the user's inputr
- returns, with the answer in the bufferf
- 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 typeo
- specifies output typec
- simply ignores the rest of the line (a comment)Let's see a real script:
n metres
o inches
f
i
* 39.37
r
b
i
/ 39.37
r
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
me at
mokomull@users.sourceforge.net
.
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 MokoMull
.
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.