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