You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
10KB

  1. #!/usr/bin/perl
  2. =pod
  3. This script reads the DeLorme Stock Symbols .dim file and writes code
  4. to be included in the .an1 format handler.
  5. You MUST have a copy of the DeLorme .dim file; you can download it
  6. from the support section of DeLorme's Web site. You want the one
  7. that contains all of the symbols.
  8. To use this script:
  9. perl make-an1sym.pl <DeLormeStockSymbols.dim >an1sym.h
  10. Copyright (C) 2005 Ronald L. Parker (babelan1perl@parkrrrr.com)
  11. and Robert Lipe
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  23. =cut
  24. # read a data structure from the input file.
  25. sub shiftunpack {
  26. my $pattern = shift;
  27. my @result = unpack( $pattern, $file );
  28. my $str = pack( $pattern, @result );
  29. $file = substr( $file, length( $str ));
  30. @result;
  31. }
  32. sub skip_bytes {
  33. my $count = shift;
  34. $file = substr( $file, $count );
  35. }
  36. sub decodeGuid {
  37. @guid = unpack( 'LSSSCCCCCC', shift );
  38. my $sub = undef;
  39. my $guid2 = sprintf( '{0x%8.8x,{0x%4.4x, 0x%4.4x, 0x%4.4x},'.
  40. ' {0x%2.2x, 0x%2.2x, 0x%2.2x, 0x%2.2x, 0x%2.2x, 0x%2.2x}}',
  41. @guid );
  42. $sub = $substitutions{ sprintf('%8.8x', @guid)};
  43. ($guid2, $sub);
  44. }
  45. sub DoImage {
  46. # image information - the 'type' we read was actually the low word of the hotspot X coord.
  47. ($hotspotxhi, $hotspoty, $unk1, $guid, $name ) =
  48. shiftunpack( 'slla[16]C/a*' );
  49. $hotspotx = $rec_type + 0x10000*$hotspotxhi;
  50. ($guid2,$sub) = decodeGuid( $guid );
  51. $name = $sub if ( $sub );
  52. print qq( {$guid2,\n "$name"},\n);
  53. }
  54. %substitutions = (
  55. # everything up to and including "mud" is defined
  56. "012dfac2", "Tractor",
  57. "012dfac3", "Combine Harvester",
  58. "012dfac7", "Front-End Loader",
  59. "fd163780", "Power Shovel",
  60. "fd163781", "Road Grader",
  61. "fd163784", "Road Roller",
  62. "fd163787", "Dump Truck",
  63. "5673d712", "Skid-Steer Loader", # Bobcat is a registered trademark
  64. "b86045ac", "Highway Sign",
  65. "1e129e95", "Orange Cone",
  66. "adee7d54", "Barricade",
  67. "a170000f", "Flagger",
  68. "a425f90e", "Construction Sign",
  69. "0805b240", "Construction Flasher",
  70. "56721a6c", "Transit",
  71. # this group of 8 arrows is defined
  72. "83f91421", "Small Arrow Left",
  73. "83f91422", "Small Arrow Right",
  74. "83f91423", "Small Arrow Up",
  75. "83f91424", "Small Arrow Down",
  76. "83f91425", "Small Arrow Up Left",
  77. "83f91426", "Small Arrow Up Right",
  78. "83f91427", "Small Arrow Down Left",
  79. "83f91428", "Small Arrow Down Right",
  80. "83f91429", "Large Arrow Left",
  81. "83f9142a", "Large Arrow Right",
  82. "83f9142b", "Large Arrow Up",
  83. "83f9142c", "Large Arrow Down",
  84. "83f9142d", "Large Arrow Down Right",
  85. "83f9142e", "Large Arrow Down Left",
  86. "83f9142f", "Large Arrow Up Left",
  87. "83f91430", "Large Arrow Up Right",
  88. "8ff0aad1", "Accommodation",
  89. "af7bf199", "Australia",
  90. "6bbcc9d1", "Blue Dome Cross",
  91. "fff920fe", "Green Dome Cross",
  92. "57e75924", "Business",
  93. "b09ef4a7", "Airplane",
  94. "f2833c22", "Amusement Recreation", # tent? on a green background
  95. "6f0317d6", "Green Square",
  96. "18a6d3c0", "Red Triangle",
  97. "86e68ea7", "Red Triangle and Green Square",
  98. "6afd74bf", "City 4",
  99. "49dfeb74", "White Square",
  100. "3eed62c6", "White Triangle",
  101. "6b521940", "Red Black Diamond Flag",
  102. "bb8ebaa3", "Yellow Diamond Flag",
  103. "8e118862", "Small Pink Square",
  104. "d0ef64c2", "Store",
  105. "a22b08fb", "Camping",
  106. "27f57c69", "Green Diamond Flag",
  107. "e07abb38", "Red Diamond Flag",
  108. "3a124ac9", "Red Green Diamond Flag",
  109. "64ed669b", "White Globe",
  110. "3cb10adc", "Yellow Globe",
  111. "2779347d", "", #???
  112. "3ad63f7b", "Black Cross",
  113. "3e89481e", "Church",
  114. "68622c10", "Small Dark Green Square",
  115. "42c6a873", "Small Black Square",
  116. "50e3b06e", "Danger",
  117. "369d0b22", "Construction Business",
  118. "10603b6c", "Airport",
  119. "8328aab7", "City 5",
  120. "96411287", "USA",
  121. "b2f98627", "Diver Down",
  122. "3fce26d0", "Light Yellow Square",
  123. "b4b68597", "Education Technology",
  124. "35d2e6a8", "Computer",
  125. "4ddc4e96", "Amusement Recreation Red",
  126. "79f58929", "Telephone Red",
  127. "0083b377", "Exit",
  128. "0c232891", "Exit with Services",
  129. "af63e7c2", "Pizza",
  130. "d419c693", "Financial Services",
  131. "70740a81", "City 3",
  132. "9a582ff6", "Food Store",
  133. "3cd31689", "", #???
  134. "952557a6", "", #??? white/black circle
  135. "03dc278c", "Driving Range",
  136. "acd28bab", "Golf Municipal",
  137. "984e7139", "Golf Private",
  138. "ec5828ab", "Golf Public",
  139. "b0120d99", "Golf Resort",
  140. "2ce7685a", "Golf Semi Private",
  141. "10397049", "Medical Service",
  142. "2fc28df6", "Home Furnishings",
  143. "910313db", "Industrial",
  144. "9e442c6e", "", #???
  145. "37e2fe4a", "", #???
  146. "3c756e09", "", #???
  147. "a1245b1c", "Manufacturing",
  148. "5bddbd7a", "Note",
  149. "cb6777e1", "City",
  150. "bc168c08", "Air Base",
  151. "a8857b0f", "Battlefield",
  152. "06db55c1", "Mining",
  153. "cc61b277", "Mountain",
  154. "fde13186", "Capital",
  155. "b14d90d1", "Route",
  156. "7eabc63f", "Overnight",
  157. "ac39d8b9", "Route End Active",
  158. "e1b9d86b", "Route End Inactive",
  159. "98712315", "Fuel Stop",
  160. "e5ea5b38", "Route Start Active",
  161. "18fd0d49", "Route Start Inactive",
  162. "2f52144b", "Route Stop Active",
  163. "faf8d826", "Route Stop Inactive",
  164. "ff44cae2", "Route Via",
  165. "5a50d59b", "Radiation Green",
  166. "19556023", "Radiation Red",
  167. "a54be251", "Electricity",
  168. "d793ff0c", "Personal Furnishings",
  169. "00f90733", "Personal Services",
  170. "ea677f24", "Telephone Black",
  171. "2d8a05b5", "Government Light",
  172. "40c64dfc", "Airport Red Square",
  173. "f27adb5d", "Propeller Aircraft",
  174. "5a718e13", "Jet Aircraft",
  175. "0a471039", "Government",
  176. "4a59da2f", "USA Regional",
  177. "f16500a9", "House 2",
  178. "7b05524d", "Picnic",
  179. "b88ad7a1", "Restaurant",
  180. "dc48a20a", "Store 2",
  181. "6b5ab040", "", # ???
  182. "153b2cff", "Blue Star",
  183. "f276f6b3", "", # ???
  184. "91d242c8", "Running",
  185. "8b0078db", "Transportation",
  186. "0599f6c9", "Fishing 2",
  187. "7389128c", "Automotive",
  188. "0362b593", "Cloudy",
  189. "f0717a94", "Partly Cloudy",
  190. "14486bbc", "Mostly Cloudy",
  191. "7a258c70", "Hurricane",
  192. "eff260d4", "Lightning",
  193. "c3d70220", "Rain",
  194. # everything else is defined
  195. # They defined two red flags. Ooops.
  196. "f2dfbc95", "Red Flag 2"
  197. );
  198. sub print_header {
  199. print <<'END';
  200. /*
  201. THIS FILE IS AUTOMATICALLY GENERATED
  202. Please change make-an1sym.pl and
  203. regenerate it rather than changing
  204. this file directly.
  205. */
  206. /*
  207. Read DeLorme drawing files (.an1) - supplemental (included by an1.c)
  208. Copyright (C) 2005 Ron Parker and Robert Lipe.
  209. This program is free software; you can redistribute it and/or modify
  210. it under the terms of the GNU General Public License as published by
  211. the Free Software Foundation; either version 2 of the License, or
  212. (at your option) any later version.
  213. This program is distributed in the hope that it will be useful,
  214. but WITHOUT ANY WARRANTY; without even the implied warranty of
  215. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  216. GNU General Public License for more details.
  217. You should have received a copy of the GNU General Public License
  218. along with this program; if not, write to the Free Software
  219. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  220. */
  221. struct defguid {
  222. GUID guid;
  223. const char *name;
  224. } default_guids[] = {
  225. END
  226. }
  227. sub print_footer {
  228. print <<'END';
  229. };
  230. int FindIconByName( const char *name, GUID *guid ) {
  231. unsigned int i = 0;
  232. for ( i = 0; i < (sizeof(default_guids)/sizeof(struct defguid)); i++ )
  233. {
  234. if ( !case_ignore_strcmp(name, default_guids[i].name)) {
  235. memcpy( guid, &(default_guids[i].guid), sizeof(GUID));
  236. return 1;
  237. }
  238. }
  239. return 0;
  240. }
  241. int FindIconByGuid( GUID *guid, char **name ) {
  242. unsigned int i = 0;
  243. for ( i = 0; i < (sizeof(default_guids)/sizeof(struct defguid)); i++ )
  244. {
  245. if ( !memcmp(guid, &default_guids[i].guid, sizeof(GUID))) {
  246. *name = default_guids[i].name;
  247. return 1;
  248. }
  249. }
  250. return 0;
  251. }
  252. END
  253. }
  254. # read file
  255. undef $/;
  256. $file = <>;
  257. # read file header
  258. ($magic, $unk1 ) = shiftunpack( 'ss' );
  259. # read bitmap info
  260. ($unk2) = shiftunpack( 'l' );
  261. print_header;
  262. while ( length($file) ) {
  263. ($rec_type) = shiftunpack( 's' );
  264. if ( $rec_type == 0x4c49 ) { # 'IL'
  265. # I don't know what this structure is, but it appears twice in my test files.
  266. ($unk10101, $unke, $unkc, $unk18_1, $unk18_2, $unkneg1_1,
  267. $unk20, $unkneg1_2, $unkneg1_3) = shiftunpack( 'lsssslsll');
  268. }
  269. elsif ( $rec_type == 0x4d42 ) { # 'BM'
  270. # This is a standard BMP file, documented in MSDN.
  271. # BITMAPFILEHEADER
  272. ($fhsize, $res_0_1, $res_0_2, $bitoffset) = shiftunpack( 'lssl' );
  273. # BITMAPINFOHEADER
  274. ($bmisize, $width, $height, $planes, $bpp, $compression,
  275. $size, $xppm, $yppm, $colused, $colimprt ) = shiftunpack( 'lllssllllll');
  276. # palette
  277. $palettesize = $bitoffset - $bmisize - 14; # 14 bytes in BMFH, including the 'BM'
  278. skip_bytes( $palettesize );
  279. # image
  280. skip_bytes( $size );
  281. }
  282. elsif ($rec_type == 0 ) { # crap
  283. ($a, $b, $c, $d, $e, $f) = shiftunpack( 'llllll' );
  284. if ( $c ) {
  285. $file = pack( 'llllll', ($a, $b, $c, $d, $e, $f)) . $file;
  286. DoImage;
  287. }
  288. }
  289. else {
  290. DoImage;
  291. }
  292. }
  293. print_footer;