1dcea9e73SCarlo-Bramini /*
2dcea9e73SCarlo-Bramini * ReactOS Calc (Unit conversion engine)
3dcea9e73SCarlo-Bramini *
4dcea9e73SCarlo-Bramini * Copyright 2007-2017, Carlo Bramini
5dcea9e73SCarlo-Bramini *
6dcea9e73SCarlo-Bramini * This program is free software; you can redistribute it and/or
7dcea9e73SCarlo-Bramini * modify it under the terms of the GNU Lesser General Public
8dcea9e73SCarlo-Bramini * License as published by the Free Software Foundation; either
9dcea9e73SCarlo-Bramini * version 2 of the License, or (at your option) any later version.
10dcea9e73SCarlo-Bramini *
11dcea9e73SCarlo-Bramini * This library is distributed in the hope that it will be useful,
12dcea9e73SCarlo-Bramini * but WITHOUT ANY WARRANTY; without even the implied warranty of
13dcea9e73SCarlo-Bramini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14dcea9e73SCarlo-Bramini * Lesser General Public License for more details.
15dcea9e73SCarlo-Bramini *
16dcea9e73SCarlo-Bramini * You should have received a copy of the GNU Lesser General Public
17dcea9e73SCarlo-Bramini * License along with this library; if not, write to the Free Software
18dcea9e73SCarlo-Bramini * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19dcea9e73SCarlo-Bramini */
20dcea9e73SCarlo-Bramini
21c2c66affSColin Finck #include "calc.h"
22c2c66affSColin Finck
23c2c66affSColin Finck /*
24c2c66affSColin Finck The conversion is made by converting the "from" unit
25c2c66affSColin Finck into the I.S. unit and then the I.S. unit is converted
26c2c66affSColin Finck into the "from" one.
27c2c66affSColin Finck
28c2c66affSColin Finck The base units for all categories are:
29c2c66affSColin Finck
30c2c66affSColin Finck ANGLE..........degrees
31c2c66affSColin Finck AREA...........square meters
32c2c66affSColin Finck CONSUMPTION....kilometers per liter
33c2c66affSColin Finck CURRENCY.......Euro
34c2c66affSColin Finck ENERGY.........joule
35c2c66affSColin Finck LENGTHS........meters
36c2c66affSColin Finck POWER..........Watt
37c2c66affSColin Finck PRESSURE.......Pascal
38c2c66affSColin Finck TEMPERATURE....kelvin
39c2c66affSColin Finck TIME...........seconds
40c2c66affSColin Finck VELOCITY.......meters per second
41c2c66affSColin Finck VOLUME.........liter
42c2c66affSColin Finck WEIGHT.........gram
43c2c66affSColin Finck
44c2c66affSColin Finck The '$' character is used as "what you read into the display".
45c2c66affSColin Finck */
46c2c66affSColin Finck typedef struct {
47c2c66affSColin Finck DWORD unit;
48c2c66affSColin Finck const char *formula_from;
49c2c66affSColin Finck const char *formula_to;
50c2c66affSColin Finck } conv_t;
51c2c66affSColin Finck
52c2c66affSColin Finck typedef struct {
53c2c66affSColin Finck const DWORD category;
54c2c66affSColin Finck const conv_t *items;
55c2c66affSColin Finck } conv_category_t;
56c2c66affSColin Finck
57c2c66affSColin Finck #define DECLARE_CONV_CAT(_category) \
58c2c66affSColin Finck { IDS_CONV_##_category, conv_##_category },
59c2c66affSColin Finck
60c2c66affSColin Finck #define DECLARE_CONV_UNIT(_category, _unit, _from, _to ) \
61c2c66affSColin Finck { IDS_##_category##_##_unit, _from, _to },
62c2c66affSColin Finck
63c2c66affSColin Finck #define DECLARE_CONV_END \
64c2c66affSColin Finck { 0, NULL, NULL },
65c2c66affSColin Finck
66c2c66affSColin Finck /*
67e5c8047eSCarlo-Bramini 1 arcminute ....... = 1/60 deg
68e5c8047eSCarlo-Bramini 1 arcsecond ....... = 1/3600 deg
69e5c8047eSCarlo-Bramini 1 gradian ......... = 0.9 deg
70e5c8047eSCarlo-Bramini 1 radian .......... = 57.29577951308233 deg
71c2c66affSColin Finck */
72c2c66affSColin Finck static const conv_t conv_ANGLE[] = {
73e5c8047eSCarlo-Bramini DECLARE_CONV_UNIT(ANGLE, ARCMINUTES, "$/60", "$*60")
74e5c8047eSCarlo-Bramini DECLARE_CONV_UNIT(ANGLE, ARCSECONDS, "$/3600", "$*3600")
75c2c66affSColin Finck DECLARE_CONV_UNIT(ANGLE, DEGREES, "$", "$")
76c2c66affSColin Finck DECLARE_CONV_UNIT(ANGLE, GRADIANS, "$*0.9", "$/0.9")
77c2c66affSColin Finck DECLARE_CONV_UNIT(ANGLE, RADIANS, "$/P*180", "$*P/180")
78c2c66affSColin Finck DECLARE_CONV_END
79c2c66affSColin Finck };
80c2c66affSColin Finck
81c2c66affSColin Finck /*
82c2c66affSColin Finck 1 acre ................ = 4840 square yd = 4046,8564224 mq
83c2c66affSColin Finck 1 acre brazil ......... =
84c2c66affSColin Finck 1 acre france ......... =
85c2c66affSColin Finck 1 acre scots .......... = 5000 mq
86c2c66affSColin Finck 1 acre us ............. = 4840*(36/39.37)^2 m = 6272640/1549.9969 m
87c2c66affSColin Finck 1 are ................. = 100 mq
88c2c66affSColin Finck 1 chou ................ = 108000*(10/33)^2 mq
89dcea9e73SCarlo-Bramini 1 danbo ............... = 991.74 mq
90c2c66affSColin Finck 1 ha .................. = 10000 mq
91dcea9e73SCarlo-Bramini 1 jeongbo ............. = 9917.4 mq
92dcea9e73SCarlo-Bramini 1 morgen hungary ...... = 5754.642 mq
93c2c66affSColin Finck 1 mu .................. = 2000/3 mq
94c2c66affSColin Finck 1 ping ................ =
95dcea9e73SCarlo-Bramini 1 pyeong .............. = 400/121 mq
96c2c66affSColin Finck 1 pyeongbangja ........ =
97c2c66affSColin Finck 1 rai ................. = 1600 mq
98c2c66affSColin Finck 1 se .................. = 1080*(10/33)^2 mq
99c2c66affSColin Finck 1 square cm ........... = 0.0001 mq
100c2c66affSColin Finck 1 square chr .......... =
101c2c66affSColin Finck 1 square fathom ....... = 1.8288^2 = 3.34450944 mq
102c2c66affSColin Finck 1 square fathom hungary = 1.8964838^2 = 3.59665080366244 mq
103c2c66affSColin Finck 1 square ft ........... = 0,09290304 mq
104c2c66affSColin Finck 1 square in ........... = 0,00064516 mq
105c2c66affSColin Finck 1 square km ........... = 1000000 mq
106c2c66affSColin Finck 1 square lar .......... =
107c2c66affSColin Finck 1 square mile ......... = 1609.344^2 = 2589988.110336 mq
108c2c66affSColin Finck 1 square mm ........... = 0,000001 mq
109c2c66affSColin Finck 1 square shaku ........ = (10/33)^2 mq
110c2c66affSColin Finck 1 square tsuen ........ =
111dcea9e73SCarlo-Bramini 1 square va ........... = 4 mq
112c2c66affSColin Finck 1 square yard ......... = 0,83612736 mq
113c2c66affSColin Finck 1 tan ................. = 10800*(10/33)^2 mq
114c2c66affSColin Finck 1 tsubo ............... = 36*(10/33)^2 mq
115c2c66affSColin Finck */
116c2c66affSColin Finck static const conv_t conv_AREA[] = {
117c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, ACRES, "$*4046,8564224", "$/4046,8564224")
118c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, ACRES_BRAZIL, "$", "$")
119c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, ACRES_FRANCE, "$", "$")
120c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, ACRES_US, "$*627264/154.99969", "$/627264*154.99969")
121c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, ACRES_SCOTS, "$*5000", "$/5000")
122c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, ARES, "$*100", "$/100")
123c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, CHOU, "$*10800000/1089", "$*1089/10800000")
124dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(AREA, DANBO, "$*991.74", "$/991.74")
125c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, HECTARES, "$*10000", "$/10000")
126dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(AREA, JEONGBO, "$*9917.4", "$/9917.4")
127c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, MORGEN_HUNGARY, "$", "$")
128c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, MU, "$*(2000/3)", "$/(2000/3)")
129c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, PING, "$", "$")
130dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(AREA, PYEONG, "$*400/121", "$*121/400")
131c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, PYEONGBANGJA, "$", "$")
132c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, RAI, "$*1600", "$/1600")
133c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SE, "$*108000/1089", "$*1089/108000")
134c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_CENTIMETERS, "$*0,0001", "$/0,0001")
135c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, SQUARE_CHR, "$", "$")
136c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_FATHOMS, "$*3.34450944", "$/3.34450944")
137c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_FATHOMS_HUNGARY, "$*3.59665080366244", "$/3.59665080366244")
138c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_FEET, "$*0,09290304", "$/0,09290304")
139c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_INCHES, "$*0,00064516", "$/0.00064516")
140c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_KILOMETERS, "$*1000000", "$/1000000")
141c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, SQUARE_LAR, "$", "$")
142c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_METER, "$", "$")
143c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_MILES, "$*2589988.110336", "$/2589988.110336")
144c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_MILLIMETERS, "$*1000000", "$/1000000")
145c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_SHAKU, "$*100/1089", "$/1089*100")
146c2c66affSColin Finck // DECLARE_CONV_UNIT(AREA, SQUARE_TSUEN, "$", "$")
147dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(AREA, SQUARE_VA, "$*4", "$/4")
148c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, SQUARE_YARD, "$*0,83612736", "$/0,83612736")
149c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, TAN, "$*1080000/1089", "$*1089/1080000")
150c2c66affSColin Finck DECLARE_CONV_UNIT(AREA, TSUBO, "$*1188/1089", "$*1089/1188")
151c2c66affSColin Finck DECLARE_CONV_END
152c2c66affSColin Finck };
153c2c66affSColin Finck
154c2c66affSColin Finck /*
155c2c66affSColin Finck 1 l/100Km = 100 km/l -> y = 100/x
156c2c66affSColin Finck 1 miles/gal uk = 1.609344/4.54609 km/l
157c2c66affSColin Finck 1 miles/gal us = 1.609344/3.785411784 km/l
158c2c66affSColin Finck */
159c2c66affSColin Finck static const conv_t conv_CONSUMPTION[] = {
160c2c66affSColin Finck DECLARE_CONV_UNIT(CONSUMPTION, KM_PER_L, "$", "$")
161c2c66affSColin Finck DECLARE_CONV_UNIT(CONSUMPTION, L_PER_100_KM, "100/$", "100/$")
162c2c66affSColin Finck DECLARE_CONV_UNIT(CONSUMPTION, MILES_GALLON_UK, "$*1.609344/4.54609", "$/1.609344*4.54609")
163c2c66affSColin Finck DECLARE_CONV_UNIT(CONSUMPTION, MILES_GALLON_US, "$*1.609344/3.785411784", "$/1.609344*3.785411784")
164c2c66affSColin Finck DECLARE_CONV_END
165c2c66affSColin Finck };
166c2c66affSColin Finck
167c2c66affSColin Finck static const conv_t conv_CURRENCY[] = {
168c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, AUSTRIAN_SCHILLING, "$/13,7603", "$*13,7603")
169c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, BELGIAN_FRANC, "$/40,3399", "$*40,3399")
170c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, CYPRIOT_POUND, "$/0,585274","$*0,585274")
171c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, DEUTSCHE_MARK, "$/1,95583", "$*1,95583")
172c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, DUTCH_GUILDER, "$/2,20371", "$*2,20371")
173c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, ESTONIAN_KROON, "$/15,6466", "$*15,6466")
174c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, EURO, "$", "$")
175c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, FINNISH_MARKKA, "$/5,94573", "$*5,94573")
176c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, FRENCH_FRANC, "$/6,55957", "$*6,55957")
177c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, GREEK_DRACHMA, "$/340,751", "$*340,751")
178c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, IRISH_POUND, "$/0,787564","$*0,787564")
179c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, ITALIAN_LIRA, "$/1936.27", "$*1936.27")
180c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, LATVIAN_LATS, "$/0,7028", "$*0,7028")
181c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, LITHUANIAN_LITAS, "$/3,45280", "$*3,45280")
182c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, LUXEMBOURG_FRANC, "$/40,3399", "$*40,3399")
183c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, MALTESE_LIRA, "$/0.42930", "$*0.42930")
184*71262981SJoachim Henze DECLARE_CONV_UNIT(CURRENCY, PORTUGUESE_ESCUDO, "$/200,482", "$*200,482")
185c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, SLOVAK_KORUNA, "$/30,126", "$*30,126")
186c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, SLOVENIAN_TOLAR, "$/239,640", "$*239,640")
187c2c66affSColin Finck DECLARE_CONV_UNIT(CURRENCY, SPANISH_PESETA, "$/166,386", "$*166,386")
188c2c66affSColin Finck DECLARE_CONV_END
189c2c66affSColin Finck };
190c2c66affSColin Finck
191c2c66affSColin Finck /*
192c2c66affSColin Finck 1 cal15 .... = 4.1855 J
193c2c66affSColin Finck 1 BTU ...... = 1055.056 J
194c2c66affSColin Finck 1 ERG ...... = 0.0000001 J
195dcea9e73SCarlo-Bramini 1 eV ....... = 0.000000000000000000160217653 J
196c2c66affSColin Finck 1 Foot-Pound = 1.3558179483314004 J
197c2c66affSColin Finck 1 IT calorie = 4.1868 J
198c2c66affSColin Finck 1 KCa ...... = 4186.8 J
199c2c66affSColin Finck 1 KJ ....... = 1000 J
200c2c66affSColin Finck 1 KWh ...... = 3600 J
201c2c66affSColin Finck 1 IUNS ..... = 4.182 J
202c2c66affSColin Finck 1 calth .... = 4.184 J
203c2c66affSColin Finck */
204c2c66affSColin Finck static const conv_t conv_ENERGY[] = {
205c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, 15_C_CALORIES, "$*4.1855", "$/4.1855")
206c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, BTUS, "$*1055.056", "$/1055.056")
207c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, ERGS, "$*.0000001", "$/.0000001")
208dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(ENERGY, EVS, "$*1.60217653/1X19", "$/1.60217653*1X19")
209c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, FOOT_POUNDS, "$*1.3558179483314004", "$/1.3558179483314004")
210c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, IT_CALORIES, "$*4.1868", "$/4.1868")
211c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, IT_KILOCALORIES, "$*4186.8", "$/4186.8")
212c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, JOULES, "$", "$")
213c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, KILOJOULES, "$*1000", "$/1000")
214c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, KILOWATT_HOURS, "$*3600", "$/3600")
215c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, NUTRITION_CALORIES, "$*4.182", "$/4.182")
216c2c66affSColin Finck DECLARE_CONV_UNIT(ENERGY, TH_CALORIES, "$*4.184", "$/4.184")
217c2c66affSColin Finck DECLARE_CONV_END
218c2c66affSColin Finck };
219c2c66affSColin Finck
220c2c66affSColin Finck /*
221c2c66affSColin Finck 1 angstrom ....... = 0.0000000001 m
222c2c66affSColin Finck 1 astronomical unit= 149598000000 m
223c2c66affSColin Finck 1 barleycorn ..... = 1/3 inch = 0.9144/108 m
224c2c66affSColin Finck 1 cm ............. = 1/100 m
225c2c66affSColin Finck 1 chain uk ....... = 22 yards = 22*0.9144 m
226c2c66affSColin Finck 1 chi ............ = 1/3 m
227c2c66affSColin Finck 1 chou ........... = 3600/33 m
228c2c66affSColin Finck 1 chr ............ =
229c2c66affSColin Finck 1 cun ............ = 1/10 chi = 1/30 m
230c2c66affSColin Finck 1 fathom ......... = 2 yard = 2*0.9144 m
231c2c66affSColin Finck 1 fathom ungary .. = 1.8964838 m (fixed)
232c2c66affSColin Finck 1 feet ........... = 12 inch = 0.9144/3 m
233c2c66affSColin Finck 1 furlong ........ = 10 chains = 220*0.9144 m
234c2c66affSColin Finck 1 gan ............ =
235c2c66affSColin Finck 1 hand ........... = 4 inches = 0.9144/9 m
236dcea9e73SCarlo-Bramini 1 hunh ........... = 1/8 nieu = 9.144/3456 m
237c2c66affSColin Finck 1 inch ........... = yard/36 = 0.9144/36 m
238c2c66affSColin Finck 1 ja ............. =
239c2c66affSColin Finck 1 jeong .......... =
240dcea9e73SCarlo-Bramini 1 kabiet ......... = 1/4 nieu = 9.144/1728 m
241c2c66affSColin Finck 1 ken ............ = 60/33 m
242dcea9e73SCarlo-Bramini 1 keub ........... = 12 nieu = 10 inch = 9.144/36 m
243c2c66affSColin Finck 1 km ............. = 1000 m
244c2c66affSColin Finck 1 lar ............ =
245c2c66affSColin Finck 1 light year ..... = 9460730472580800 m
246c2c66affSColin Finck 1 link uk ........ = 0.01 chains = 0.22*0.9144 m
247c2c66affSColin Finck 1 micron ......... = 0.000001 m
248c2c66affSColin Finck 1 mile ........... = 1760 yards = 1609.344 m
249c2c66affSColin Finck 1 millimeter ..... = 1/1000 m
250c2c66affSColin Finck 1 nautical mile .. = 1852 m
251dcea9e73SCarlo-Bramini 1 nieu ........... = 10/12 inch = 9.144/432 m
252c2c66affSColin Finck 1 parsec ......... = 30856800000000000 m
253c2c66affSColin Finck 1 pica ........... = yard/216 = 0.9144/216 m
254dcea9e73SCarlo-Bramini 1 ri japan ....... = 129600/33 m
255dcea9e73SCarlo-Bramini 1 ri korea ....... = 12960/33 m
256c2c66affSColin Finck 1 rod ............ = 5.0292 m
257dcea9e73SCarlo-Bramini 1 sawk ........... = 2 keub = 20 inch = 9.144/18 m
258dcea9e73SCarlo-Bramini 1 sen ............ = 20 va = 40.64 m
259c2c66affSColin Finck 1 shaku .......... = 10/33 m
260c2c66affSColin Finck 1 span ........... = 9 inches = 0.9144/4 m
261c2c66affSColin Finck 1 sun ............ = 1/33 m
262c2c66affSColin Finck 1 tsuen .......... =
263dcea9e73SCarlo-Bramini 1 va ............. = 4 sawk = 80 inch = 2.032 m
264c2c66affSColin Finck 1 yard ........... = 0.9144 m
265dcea9e73SCarlo-Bramini 1 yote ........... = 400 sen = 16256 m
266dcea9e73SCarlo-Bramini 1 zhang .......... = 3+1/3 m = 10/3 m
267c2c66affSColin Finck */
268c2c66affSColin Finck static const conv_t conv_LENGTH[] = {
269dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, ANGSTROMS, "$/1X10", "$*1X10")
270c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, ASTRONOMICAL_UNITS, "$*149598000000", "$/149598000000")
271c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, BARLEYCORNS, "$*0.9144/108", "$/0.9144*108")
272c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, CENTIMETERS, "$/100", "$*100")
273c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, CHAINS_UK, "$*20.1168", "$/20.1168")
274c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, CHI, "$/3", "$*3")
275c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, CHOU, "$*3600/33", "$*33/3600")
276c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, CHR, "$", "$")
277c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, CUN, "$/30", "$*30")
278c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, FATHOMS, "$*1.8288", "$/1.8288")
279c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, FATHOMS_HUNGARY, "$*1.8964838", "$/1.8964838")
280c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, FEET, "$*0.3048", "$/0.3048")
281c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, FURLONGS, "$*201.168", "$/201.168")
282c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, GAN, "$", "$")
283c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, HANDS, "$*0,1016", "$/0,1016")
284dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, HUNH, "$*9.144/3456", "$/9.144*3456")
285c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, INCHES, "$*0.0254", "$/0.0254")
286c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, JA, "$", "$")
287c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, JEONG, "$", "$")
288dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, KABIET, "$*9.144/1728", "$/9.144*1728")
289c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, KEN, "$*60/33", "$*33/60")
290dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, KEUB, "$*9.144/36", "$/9.144*36")
291c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, KILOMETERS, "$*1000", "$/1000")
292c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, LAR, "$", "$")
293c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, LIGHT_YEARS, "$*9460730472580800", "$/9460730472580800")
294c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, LINKS_UK, "$*0.201168", "$/0.201168")
295c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, METERS, "$", "$")
296c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, MICRONS, "$*0.000001", "$/0.000001")
297c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, MILES, "$*1609.344", "$/1609.344")
298c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, MILLIMETERS, "$/1000", "$*1000")
299c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, NAUTICAL_MILES, "$*1852", "$/1852")
300dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, NIEU, "$*9.144/432", "$/9.144*432")
301dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, PARSECS, "$*3.085678X16", "$/3.085678X16")
302c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, PICAS, "$*0.9144/216", "$/0.9144*216")
303c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, RODS, "$*5.0292", "$/5.0292")
304dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, RI_JAPAN, "$*129600/33", "$*33/129600")
305dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, RI_KOREA, "$*12960/33", "$*33/12960")
306dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, SAWK, "$*9.144/18", "$/9.144*18")
307dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, SEN, "$*40.64", "$/40.64")
308c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, SHAKU, "$*10/33", "$*33/10")
309c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, SPAN, "$*0.9144/4", "$*4/0.9144")
310c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, SUN, "$*1/33", "$*33")
311c2c66affSColin Finck // DECLARE_CONV_UNIT(LENGTH, TSUEN, "$", "$")
312dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, VA, "$*2.032", "$/2.032")
313c2c66affSColin Finck DECLARE_CONV_UNIT(LENGTH, YARDS, "$*0.9144", "$/0.9144")
314dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, YOTE, "$*16256", "$/16256")
315dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(LENGTH, ZHANG, "$/0.3", "$*0.3")
316c2c66affSColin Finck DECLARE_CONV_END
317c2c66affSColin Finck };
318c2c66affSColin Finck
319c2c66affSColin Finck /*
320c2c66affSColin Finck 1 BTU/min = 17.5842642 W
321c2c66affSColin Finck 1 Foot-pound/minute = 0.02259696580552333 W
322c2c66affSColin Finck 1 hp = 745.69987158227022 W
323c2c66affSColin Finck 1 KW = 1000 W
324c2c66affSColin Finck 1 MW = 1000000 W
325c2c66affSColin Finck */
326c2c66affSColin Finck static const conv_t conv_POWER[] = {
327c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, BTUS_PER_MINUTE, "$*17.5842642", "$/17.5842642")
328c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, FPS_PER_MINUTE, "$*0.02259696580552333", "$/0.02259696580552333")
329c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, HORSEPOWER, "$*745.69987158227022", "$/745.69987158227022")
330c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, KILOWATTS, "$*1000", "$/1000")
331c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, MEGAWATTS, "$*1000000", "$/1000000")
332c2c66affSColin Finck DECLARE_CONV_UNIT(POWER, WATTS, "$", "$")
333c2c66affSColin Finck DECLARE_CONV_END
334c2c66affSColin Finck };
335c2c66affSColin Finck
336c2c66affSColin Finck /*
337c2c66affSColin Finck 1 ATM = 101325 Pa
338c2c66affSColin Finck 1 BAR = 100000 Pa
339c2c66affSColin Finck 1 hPa = 100 Pa
340c2c66affSColin Finck 1 kPa = 1000 Pa
341c2c66affSColin Finck 1 mm HG = 133.322 Pa
342c2c66affSColin Finck 1 psi = 6894.757 Pa
343c2c66affSColin Finck */
344c2c66affSColin Finck static const conv_t conv_PRESSURE[] = {
345c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, ATMOSPHERES, "$*101325", "$/101325")
346c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, BARS, "$*100000", "$/100000")
347c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, HECTOPASCALS, "$*100", "$/100")
348c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, KILOPASCALS, "$*1000", "$/1000")
349c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, MM_OF_MERCURY, "$*133.322", "$/133.322")
350c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, PASCALS, "$", "$")
351c2c66affSColin Finck DECLARE_CONV_UNIT(PRESSURE, PSI, "$*6894.757", "$/6894.757")
352c2c66affSColin Finck DECLARE_CONV_END
353c2c66affSColin Finck };
354c2c66affSColin Finck
355c2c66affSColin Finck /*
356c2c66affSColin Finck 1 day ....... = 86400 s
357c2c66affSColin Finck 1 hour ...... = 3600 s
358c2c66affSColin Finck 1 microsecond = 0.000001 s
359c2c66affSColin Finck 1 millisecond = 0.001 s
360c2c66affSColin Finck 1 nanosecond. = 0.000000001 s
361c2c66affSColin Finck 1 minute .... = 60 s
362c2c66affSColin Finck 1 week ...... = 669600 s
363c2c66affSColin Finck */
364c2c66affSColin Finck static const conv_t conv_TIME[] = {
365c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, MINUTES, "$*60", "$/60")
366c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, DAYS, "$*86400", "$/86400")
367c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, HOURS, "$*3600", "$/3600")
368c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, MILLISECONDS, "$*0.001", "$/0.001")
369c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, MICROSECONDS, "$*0.000001", "$/0.000001")
370c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, NANOSECONDS, "$*0.000000001", "$/0.000000001")
371c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, SECONDS, "$", "$")
372c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, WEEKS, "$*604800", "$/604800")
373c2c66affSColin Finck DECLARE_CONV_UNIT(TIME, YEARS, "$*31556952", "$/31556952")
374c2c66affSColin Finck DECLARE_CONV_END
375c2c66affSColin Finck };
376c2c66affSColin Finck
377c2c66affSColin Finck /*
378c2c66affSColin Finck C = K - 273.15
379c2c66affSColin Finck F = K * 9/5 - 459.67
380c2c66affSColin Finck R = K * 9/5
381c2c66affSColin Finck */
382c2c66affSColin Finck static const conv_t conv_TEMPERATURE[] = {
383c2c66affSColin Finck DECLARE_CONV_UNIT(TEMPERATURE, CELSIUS, "$+273.15", "$-273.15")
384c2c66affSColin Finck DECLARE_CONV_UNIT(TEMPERATURE, FAHRENHEIT, "($+459.67)*5/9", "$*9/5-459.67")
385c2c66affSColin Finck DECLARE_CONV_UNIT(TEMPERATURE, KELVIN, "$", "$")
386c2c66affSColin Finck DECLARE_CONV_UNIT(TEMPERATURE, RANKINE, "$*5/9", "$*9/5")
387c2c66affSColin Finck DECLARE_CONV_END
388c2c66affSColin Finck };
389c2c66affSColin Finck
390c2c66affSColin Finck /*
391c2c66affSColin Finck 1 cm/s = 0.01 m/s
392c2c66affSColin Finck 1 f/h = 0.0000846666667 m/s
393c2c66affSColin Finck 1 f/s = 0.3048 m/s
394c2c66affSColin Finck 1 Km/h = 10/36 m/s -> 0.27778 m/s
395c2c66affSColin Finck 1 knot = 18.52/36 m/s -> 0.51444444 m/s
396c2c66affSColin Finck 1 mach = 340.3 m/s
397c2c66affSColin Finck 1 mph = 0.44704 m/s
398c2c66affSColin Finck */
399c2c66affSColin Finck static const conv_t conv_VELOCITY[] = {
400c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, CMS_SECOND, "$*.01", "$/.01")
401c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, FEET_SECOND, "$*.3048", "$/.3048")
402c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, FEET_HOUR, "$*.0000846666667", "$/.0000846666667")
403c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, KILOMETERS_HOUR, "$*10/36", "$*36/10")
404c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, KNOTS, "$*18.52/36", "$*36/18.52")
405c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, MACH, "$*340.3", "$/340.3")
406c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, METERS_SECOND, "$", "$")
407c2c66affSColin Finck DECLARE_CONV_UNIT(VELOCITY, MILES_HOUR, "$*.44704", "$/.44704")
408c2c66affSColin Finck DECLARE_CONV_END
409c2c66affSColin Finck };
410c2c66affSColin Finck
411c2c66affSColin Finck /*
412c2c66affSColin Finck 1 barrel uk ...... = 163.65924 l
413c2c66affSColin Finck 1 barrel oil ..... = 158.987295 l
414dcea9e73SCarlo-Bramini 1 bun ............ = 1000 l
415c2c66affSColin Finck 1 bushel uk ...... = 36.36872 l
416c2c66affSColin Finck 1 bushel us ...... = 35.23907017 l
417c2c66affSColin Finck 1 cubic cm ...... = 0.001 l
418c2c66affSColin Finck 1 cubic feet ..... = 28.316846 l
419c2c66affSColin Finck 1 cubic inch ..... = 0.016387064 l
420c2c66affSColin Finck 1 cubic meter .... = 1000 l
421c2c66affSColin Finck 1 cubic yard ..... = 764.554857 l
422c2c66affSColin Finck 1 doe ............ =
423c2c66affSColin Finck 1 fluid ounce uk = 0.0284130625 l
424c2c66affSColin Finck 1 fluid ounce us = 0.0295735295625 l
425c2c66affSColin Finck 1 gallon uk ...... = 4.54609 l
426c2c66affSColin Finck 1 gallon dry us .. = 4.40488377086 l
427c2c66affSColin Finck 1 gallon liquid us = 3.785411784 l
428c2c66affSColin Finck 1 gou ............ = 0.1809 l
429c2c66affSColin Finck 1 hop ............ =
430c2c66affSColin Finck 1 icce ........... =
431dcea9e73SCarlo-Bramini 1 kwian .......... = 2000 l
432c2c66affSColin Finck 1 mal ............ =
433c2c66affSColin Finck 1 milliliter ..... = 0.001 l
434c2c66affSColin Finck 1 pint uk ........ = 0.56826125 l
435c2c66affSColin Finck 1 pint dry us .... = 0.5506104713575 l
436c2c66affSColin Finck 1 pint liquid us = 0.473176473 l
437c2c66affSColin Finck 1 quart uk ....... = 1.1365225 l
438c2c66affSColin Finck 1 quart dry us ... = 1.101220942715 l
439c2c66affSColin Finck 1 quart liquid us = 0.946352946 l
440c2c66affSColin Finck 1 seki ........... =
441c2c66affSColin Finck 1 syou ........... =
442dcea9e73SCarlo-Bramini 1 tananloung ..... = 1 l
443dcea9e73SCarlo-Bramini 1 tang ........... = 20 l
444c2c66affSColin Finck 1 to ............. = 18040 l
445c2c66affSColin Finck */
446c2c66affSColin Finck static const conv_t conv_VOLUME[] = {
447c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, BARRELS_UK, "$*163.65924", "$/163.65924")
448c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, BARRELS_OIL, "$*158.987295", "$/158.987295")
449dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(VOLUME, BUN, "$*1000", "$/1000")
450c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, BUSHELS_UK, "$*36.36872", "$/36.36872")
451c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, BUSHELS_US, "$*35.23907017", "$/35.23907017")
452c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, CUBIC_CENTIMETERS, "$*0.001", "$/0.001")
453c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, CUBIC_FEET, "$*28.316846", "$/28.316846")
454c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, CUBIC_INCHES, "$*0.016387064", "$/0.016387064")
455c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, CUBIC_METERS, "$*1000", "$/1000")
456c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, CUBIC_YARDS, "$*764.554857", "$/764.554857")
457c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, DOE, "$", "$")
458c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, FLUID_OUNCES_UK, "$*0.0284130625", "$/0.0284130625")
459c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, FLUID_OUNCES_US, "$*0.0295735295625", "$/0.0295735295625")
460c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, GALLONS_UK, "$*4.54609", "$/4.54609")
461c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, GALLONS_DRY_US, "$*4.40488377086", "$/4.40488377086")
462c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, GALLONS_LIQUID_US, "$*3.785411784", "$/3.785411784")
463c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, GOU, "$*0.1809", "$/0.1809")
464c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, HOP, "$", "$")
465c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, ICCE, "$", "$")
466dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(VOLUME, KWIAN, "$*2000", "$/2000")
467c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, LITERS, "$", "$")
468c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, MAL, "$", "$")
469c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, MILLILITERS, "$*0.001", "$/0.001")
470c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, PINTS_UK, "$*0.56826125", "$/0.56826125")
471c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, PINTS_DRY_US, "$*0.5506104713575", "$/0.5506104713575")
472c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, PINTS_LIQUID_US, "$*0.473176473", "$/0.473176473")
473c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, QUARTS_UK, "$*1.1365225", "$/1.1365225")
474c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, QUARTS_DRY_US, "$*1.101220942715", "$/1.101220942715")
475c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, QUARTS_LIQUID_US, "$*0.946352946", "$/0.946352946")
476c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, SEKI, "$", "$")
477c2c66affSColin Finck // DECLARE_CONV_UNIT(VOLUME, SYOU, "$", "$")
478dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(VOLUME, TANANLOUNG, "$", "$")
479dcea9e73SCarlo-Bramini DECLARE_CONV_UNIT(VOLUME, TANG, "$*20", "$/20")
480c2c66affSColin Finck DECLARE_CONV_UNIT(VOLUME, TO, "$*18040", "$/18040")
481c2c66affSColin Finck DECLARE_CONV_END
482c2c66affSColin Finck };
483c2c66affSColin Finck
484c2c66affSColin Finck /*
485c2c66affSColin Finck 1 baht ............ = 12.244 g
486c2c66affSColin Finck 1 carat ........... = 0.2 g
487c2c66affSColin Finck 1 chung ........... =
488c2c66affSColin Finck 1 don ............. =
489c2c66affSColin Finck 1 geun ............ =
490c2c66affSColin Finck 1 gwan ............ =
491c2c66affSColin Finck 1 harb ............ =
492c2c66affSColin Finck 1 jin china ....... =
493c2c66affSColin Finck 1 jin taiwan ...... =
494c2c66affSColin Finck 1 Kan ............. = 3750 g
495c2c66affSColin Finck 1 Kilograms ....... = 1000 g
496c2c66affSColin Finck 1 Kin ............. = 600 g
497c2c66affSColin Finck 1 Liang China ..... =
498c2c66affSColin Finck 1 Liang Taiwan .... =
499c2c66affSColin Finck 1 monme ........... = 3.75 g
500c2c66affSColin Finck 1 ounce avoirdupois = 28.349523125 g
501c2c66affSColin Finck 1 ounce troy ...... = 31.1034768 g
502c2c66affSColin Finck 1 pound ........... = 453.59237 g
503c2c66affSColin Finck 1 quintal metric .. = 100000 g
504c2c66affSColin Finck 1 saloung ......... =
505c2c66affSColin Finck 1 stone ........... = 6350.29318 g
506c2c66affSColin Finck 1 tamlung ......... =
507c2c66affSColin Finck 1 ton ............. = 1000000 g
508c2c66affSColin Finck 1 ton uk .......... = 1016046.9088 g // long ton
509c2c66affSColin Finck 1 ton us .......... = 907184.74 g // short ton
510c2c66affSColin Finck */
511dcea9e73SCarlo-Bramini /*
512dcea9e73SCarlo-Bramini 1 chang = 20 tamlung
513dcea9e73SCarlo-Bramini 1 tamlung = 4 baht
514dcea9e73SCarlo-Bramini 1 baht = 4 saloung
515dcea9e73SCarlo-Bramini 1 saloung =
516dcea9e73SCarlo-Bramini
517dcea9e73SCarlo-Bramini 1 chang = 6/5 kg = 1200 g
518dcea9e73SCarlo-Bramini 1 tamlung = 1/20 chang = 60 g
519dcea9e73SCarlo-Bramini 1 baht = 1/4 tamlung = 15 g
520dcea9e73SCarlo-Bramini 1 saloung = 1/4 bath = 15/4 g
521dcea9e73SCarlo-Bramini */
522c2c66affSColin Finck static const conv_t conv_WEIGHT[] = {
523c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, BAHT, "$*12.244", "$/12.244")
524c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, CARATS, "$*0.2", "$/0.2")
525c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, CHUNG, "$", "$")
526c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, DON, "$", "$")
527c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, GEUN, "$", "$")
528c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, GRAMS, "$", "$")
529c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, GWAN, "$", "$")
530c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, HARB, "$", "$")
531c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, JIN_CHINA, "$", "$")
532c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, JIN_TAIWAN, "$", "$")
533c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, KAN, "$*3750", "$/3750")
534c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, KILOGRAMS, "$*1000", "$/1000")
535c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, KIN, "$*600", "$/600")
536c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, LIANG_CHINA, "$", "$")
537c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, LIANG_TAIWAN, "$", "$")
538c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, MONME, "$*3.75", "$/3.75")
539c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, OUNCES_AVOIRDUPOIS, "$*28.349523125", "$/28.349523125")
540c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, OUNCES_TROY, "$*31.1034768", "$/31.1034768")
541c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, POUNDS, "$*453.59237", "$/453.59237")
542c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, QUINTAL_METRIC, "$*100000", "$/100000")
543c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, SALOUNG, "$", "$")
544c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, STONES, "$*6350.29318", "$/6350.29318")
545c2c66affSColin Finck // DECLARE_CONV_UNIT(WEIGHT, TAMLUNG, "$", "$")
546c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, TONNES, "$*1000000", "$/1000000")
547c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, TONS_UK, "$*1016046.9088", "$/1016046.9088")
548c2c66affSColin Finck DECLARE_CONV_UNIT(WEIGHT, TONS_US, "$*907184.74", "$/907184.74")
549c2c66affSColin Finck DECLARE_CONV_END
550c2c66affSColin Finck };
551c2c66affSColin Finck
552c2c66affSColin Finck static const conv_category_t conv_table[] = {
553c2c66affSColin Finck DECLARE_CONV_CAT(ANGLE)
554c2c66affSColin Finck DECLARE_CONV_CAT(AREA)
555c2c66affSColin Finck DECLARE_CONV_CAT(CONSUMPTION)
556c2c66affSColin Finck DECLARE_CONV_CAT(CURRENCY)
557c2c66affSColin Finck DECLARE_CONV_CAT(ENERGY)
558c2c66affSColin Finck DECLARE_CONV_CAT(LENGTH)
559c2c66affSColin Finck DECLARE_CONV_CAT(POWER)
560c2c66affSColin Finck DECLARE_CONV_CAT(PRESSURE)
561c2c66affSColin Finck DECLARE_CONV_CAT(TIME)
562c2c66affSColin Finck DECLARE_CONV_CAT(TEMPERATURE)
563c2c66affSColin Finck DECLARE_CONV_CAT(VELOCITY)
564c2c66affSColin Finck DECLARE_CONV_CAT(VOLUME)
565c2c66affSColin Finck DECLARE_CONV_CAT(WEIGHT)
566c2c66affSColin Finck };
567c2c66affSColin Finck
ConvExecute(HWND hWnd)568c2c66affSColin Finck void ConvExecute(HWND hWnd)
569c2c66affSColin Finck {
570c2c66affSColin Finck DWORD c_cat = (DWORD)SendDlgItemMessage(hWnd, IDC_COMBO_CATEGORY, CB_GETCURSEL, 0, 0);
571c2c66affSColin Finck const conv_t *items = NULL;
572c2c66affSColin Finck DWORD from = SendDlgItemMessage(hWnd, IDC_COMBO_FROM, CB_GETCURSEL, 0, 0);
573c2c66affSColin Finck DWORD to = SendDlgItemMessage(hWnd, IDC_COMBO_TO, CB_GETCURSEL, 0, 0);
574c2c66affSColin Finck TCHAR txt_cb[128];
575c2c66affSColin Finck TCHAR txt[128];
576c2c66affSColin Finck const conv_t *item;
577c2c66affSColin Finck
578c2c66affSColin Finck /* do nothing if the indexes point to the same unit */
579c2c66affSColin Finck if (from == to)
580c2c66affSColin Finck return;
581c2c66affSColin Finck
582c2c66affSColin Finck /* Search correct category, since it can be sorted too */
583c2c66affSColin Finck SendDlgItemMessage(hWnd, IDC_COMBO_CATEGORY, CB_GETLBTEXT, c_cat, (LPARAM)txt_cb);
584c2c66affSColin Finck for (c_cat=0; c_cat < SIZEOF(conv_table); c_cat++) {
585c2c66affSColin Finck LoadString(calc.hInstance, conv_table[c_cat].category, txt, SIZEOF(txt));
586c2c66affSColin Finck if (!_tcscmp(txt_cb, txt)) {
587c2c66affSColin Finck items = conv_table[c_cat].items;
588c2c66affSColin Finck break;
589c2c66affSColin Finck }
590c2c66affSColin Finck }
591c2c66affSColin Finck
592c2c66affSColin Finck /* The units can be sorted, so I must search the exact match */
593c2c66affSColin Finck item = items;
594c2c66affSColin Finck SendDlgItemMessage(hWnd, IDC_COMBO_FROM, CB_GETLBTEXT, from, (LPARAM)txt_cb);
595c2c66affSColin Finck while (item->unit) {
596c2c66affSColin Finck LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
597c2c66affSColin Finck if (!_tcscmp(txt_cb, txt)) {
598c2c66affSColin Finck from = item-items;
599c2c66affSColin Finck break;
600c2c66affSColin Finck }
601c2c66affSColin Finck item++;
602c2c66affSColin Finck }
603c2c66affSColin Finck SendDlgItemMessage(hWnd, IDC_COMBO_TO, CB_GETLBTEXT, to, (LPARAM)txt_cb);
604c2c66affSColin Finck item = items;
605c2c66affSColin Finck while (item->unit) {
606c2c66affSColin Finck LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
607c2c66affSColin Finck if (!_tcscmp(txt_cb, txt)) {
608c2c66affSColin Finck to = item-items;
609c2c66affSColin Finck break;
610c2c66affSColin Finck }
611c2c66affSColin Finck item++;
612c2c66affSColin Finck }
613c2c66affSColin Finck
614c2c66affSColin Finck calc.Convert[0].data = (char *)items[from].formula_from;
615c2c66affSColin Finck calc.Convert[1].data = (char *)items[to].formula_to;
616c2c66affSColin Finck calc.Convert[0].wm_msg = WM_HANDLE_FROM;
617c2c66affSColin Finck calc.Convert[1].wm_msg = WM_HANDLE_TO;
618c2c66affSColin Finck PostMessage(hWnd, WM_START_CONV, 0, MAKELPARAM(0, WM_HANDLE_FROM));
619c2c66affSColin Finck }
620c2c66affSColin Finck
ConvAdjust(HWND hWnd,int n_cat)621c2c66affSColin Finck void ConvAdjust(HWND hWnd, int n_cat)
622c2c66affSColin Finck {
623c2c66affSColin Finck TCHAR txt[128];
624c2c66affSColin Finck TCHAR txt_cat[128];
625c2c66affSColin Finck HWND hFromWnd = GetDlgItem(hWnd, IDC_COMBO_FROM);
626c2c66affSColin Finck HWND hToWnd = GetDlgItem(hWnd, IDC_COMBO_TO);
627c2c66affSColin Finck const conv_t *item;
628c2c66affSColin Finck unsigned int n;
629c2c66affSColin Finck
630c2c66affSColin Finck SendDlgItemMessage(hWnd, IDC_COMBO_CATEGORY, CB_GETLBTEXT, n_cat, (LPARAM)txt_cat);
631c2c66affSColin Finck for (n=0; n<SIZEOF(conv_table); n++) {
632c2c66affSColin Finck item = conv_table[n].items;
633c2c66affSColin Finck LoadString(calc.hInstance, conv_table[n].category, txt, SIZEOF(txt));
634c2c66affSColin Finck if (!_tcscmp(txt_cat, txt))
635c2c66affSColin Finck break;
636c2c66affSColin Finck }
637c2c66affSColin Finck
638c2c66affSColin Finck SendMessage(hFromWnd, CB_RESETCONTENT, 0, 0);
639c2c66affSColin Finck SendMessage(hToWnd, CB_RESETCONTENT, 0, 0);
640c2c66affSColin Finck while (item->unit) {
641c2c66affSColin Finck LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
642c2c66affSColin Finck SendMessage(hFromWnd, CB_ADDSTRING, 0, (LPARAM)txt);
643c2c66affSColin Finck SendMessage(hToWnd, CB_ADDSTRING, 0, (LPARAM)txt);
644c2c66affSColin Finck item++;
645c2c66affSColin Finck }
646c2c66affSColin Finck SendMessage(hFromWnd, CB_SETCURSEL, 0, 0);
647c2c66affSColin Finck SendMessage(hToWnd, CB_SETCURSEL, 0, 0);
648c2c66affSColin Finck }
649c2c66affSColin Finck
ConvInit(HWND hWnd)650c2c66affSColin Finck void ConvInit(HWND hWnd)
651c2c66affSColin Finck {
652c2c66affSColin Finck HWND hCatWnd = GetDlgItem(hWnd, IDC_COMBO_CATEGORY);
653c2c66affSColin Finck TCHAR txt[128];
654c2c66affSColin Finck unsigned int n;
655c2c66affSColin Finck
656c2c66affSColin Finck /* Fill category combo */
657c2c66affSColin Finck for (n=0; n<SIZEOF(conv_table); n++) {
658c2c66affSColin Finck LoadString(calc.hInstance, conv_table[n].category, txt, SIZEOF(txt));
659c2c66affSColin Finck SendMessage(hCatWnd, CB_ADDSTRING, 0, (LPARAM)txt);
660c2c66affSColin Finck }
661c2c66affSColin Finck SendMessage(hCatWnd, CB_SETCURSEL, 0, 0);
662c2c66affSColin Finck ConvAdjust(hWnd, 0);
663c2c66affSColin Finck }
664c2c66affSColin Finck
665