2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Program that makes country files
20 struct IntCountryPrefs
*ca_Data
;
23 extern struct IntCountryPrefs
30 bosnia_herzegovinaPrefs
,
85 /* Please keep this in alphabetical order, ie the order of Latin 1.
86 Character set of this file is also Latin 1 */
88 struct CountryEntry CountryArray
[] =
90 { "andorra" , &andorraPrefs
},
91 { "angola" , &angolaPrefs
},
92 { "argentina" , &argentinaPrefs
},
93 { "australia" , &australiaPrefs
},
94 { "austria" , &austriaPrefs
},
95 { "belgium" , &belgiumPrefs
},
96 { "bosnia_herzegovina", &bosnia_herzegovinaPrefs
},
97 { "brazil" , &brazilPrefs
},
98 { "bulgaria" , &bulgariaPrefs
},
99 { "canada" , &canadaPrefs
},
100 { "cape_verde" , &cape_verdePrefs
},
101 { "china" , &chinaPrefs
},
102 { "costa_rica" , &costa_ricaPrefs
},
103 { "croatia" , &croatiaPrefs
},
104 { "czech_republic" , &czech_republicPrefs
},
105 { "denmark" , &denmarkPrefs
},
106 { "east_timor" , &east_timorPrefs
},
107 { "estonia" , &estoniaPrefs
},
108 { "finland" , &finlandPrefs
},
109 { "france" , &francePrefs
},
110 { "germany" , &germanyPrefs
},
111 { "great_britain" , &great_britainPrefs
},
112 { "greece" , &greecePrefs
},
113 { "haiti" , &haitiPrefs
},
114 { "hungary" , &hungaryPrefs
},
115 { "iceland" , &icelandPrefs
},
116 { "indonesia" , &indonesiaPrefs
},
117 { "iran" , &iranPrefs
},
118 { "ireland" , &irelandPrefs
},
119 { "italy" , &italyPrefs
},
120 { "japan" , &japanPrefs
},
121 { "latvia" , &latviaPrefs
},
122 { "liechtenstein" , &liechtensteinPrefs
},
123 { "lithuania" , &lithuaniaPrefs
},
124 { "luxembourg" , &luxembourgPrefs
},
125 { "malta" , &maltaPrefs
},
126 { "moldova" , &moldovaPrefs
},
127 { "monaco" , &monacoPrefs
},
128 { "montenegro" , &montenegroPrefs
},
129 { "new_zealand" , &new_zealandPrefs
},
130 { "netherlands" , &netherlandsPrefs
},
131 { "norway" , &norwayPrefs
},
132 { "poland" , &polandPrefs
},
133 { "portugal" , &portugalPrefs
},
134 { "romania" , &romaniaPrefs
},
135 { "russia" , &russiaPrefs
},
136 { "san_marino" , &san_marinoPrefs
},
137 { "slovakia" , &slovakiaPrefs
},
138 { "slovenia" , &sloveniaPrefs
},
139 { "south_korea" , &south_koreaPrefs
},
140 { "spain" , &spainPrefs
},
141 { "sweden" , &swedenPrefs
},
142 { "switzerland" , &switzerlandPrefs
},
143 { "taiwan" , &taiwanPrefs
},
144 { "turkey" , &turkeyPrefs
},
145 { "ukraine" , &ukrainePrefs
},
146 { "united_kingdom" , &united_kingdomPrefs
},
147 { "united_states" , &united_statesPrefs
},
148 { "vatican_city" , &vatican_cityPrefs
},
149 { "yugoslavia" , &yugoslaviaPrefs
},
153 /* This is equivalent to the start of the catalog file.
154 It is a series of strings, so that the endianness is
159 "FORM" "\x00\x00\x00\x00" "PREF"
161 "PRHD" "\x00\x00\x00\x06"
162 "\x00\x00\x00\x00\x00\x00"
167 "CTRY" "\x00\x00\x00\x00"
172 "FVER" "\x00\x00\x00\x00"
177 "NNAM" "\x00\x00\x00\x00"
182 "FLAG" "\x00\x00\x00\x00"
186 char iffpad
[] = "\x00";
188 void convertEndianness(struct CountryPrefs
*cp
);
189 unsigned long getCountryPrefsSize(void);
190 unsigned long getCountryPrefsVers(struct IntCountryPrefs
*cp
);
191 unsigned long getCountryPrefsFlag(struct IntCountryPrefs
*cp
);
192 unsigned long getCountryNames(struct IntCountryPrefs
*cp
);
194 int writeChunk(FILE *fp
, char *header
, void *buffer
, int len
,
195 char *progname
, char *filename
)
197 header
[4] = (len
& (0xFF000000)) >> 24;
198 header
[5] = (len
& (0x00FF0000)) >> 16;
199 header
[6] = (len
& (0x0000FF00)) >> 8;
200 header
[7] = (len
& (0x000000FF));
202 /* Write out the IFF header... */
203 if(fwrite(header
, 8, 1, fp
) < 1)
205 printf("%s: Error writing chunk header for %s.\n", progname
, filename
);
210 if(fwrite(buffer
, len
, 1, fp
) < 1)
212 printf("%s: Error writing chunk data for %s.\n", progname
, filename
);
216 if ((len
& 1) && (fwrite(iffpad
, 1, 1, fp
) < 1))
218 printf("%s: Error padding chunk for %s.\n", progname
, filename
);
225 int doCountry(struct IntCountryPrefs
*cp
, char *progname
, char *filename
)
229 char *cpVers
, *cpFlag
, *cpNames
;
231 fp
= fopen(filename
, "w");
234 printf("%s: Could not open file %s\n", progname
, filename
);
238 /* Adjust the size of the IFF file if necessary ... */
239 if ((cpVers
= getCountryPrefsVers(cp
)) != NULL
)
241 size
+= strlen(cpVers
);
244 if ((cpFlag
= getCountryPrefsFlag(cp
)) != NULL
)
246 size
+= strlen(cpFlag
);
249 if ((cpNames
= getCountryNames(cp
)) != NULL
)
251 size
+= strlen(cpNames
);
255 iffheader
[4] = (size
& (0xFF000000)) >> 24;
256 iffheader
[5] = (size
& (0x00FF0000)) >> 16;
257 iffheader
[6] = (size
& (0x0000FF00)) >> 8;
258 iffheader
[7] = (size
& (0x000000FF));
260 /* Write out the IFF header... */
261 if(fwrite(iffheader
, 26, 1, fp
) < 1)
263 printf("%s: Error writing IFF header for %s.\n", progname
, filename
);
268 /* Write out the main Country Prefs Chunk ... */
269 convertEndianness((struct CountryPrefs
*)cp
);
271 if(writeChunk(fp
, ctryheader
, cp
, getCountryPrefsSize(), progname
, filename
))
273 printf("%s: Error writing country data chunk %s.\n", progname
, filename
);
277 /* Write out the Version String Chunk if appropriate ... */
280 if(writeChunk(fp
, versheader
, cpVers
, strlen(cpVers
) + 1, progname
, filename
))
282 printf("%s: Error writing country version string chunk %s.\n", progname
, filename
);
287 /* Write out the NativeNames Chunk if appropriate ... */
290 if(writeChunk(fp
, nnameheader
, cpNames
, strlen(cpNames
) + 1, progname
, filename
))
292 printf("%s: Error writing country native-names string chunk %s.\n", progname
, filename
);
297 /* Write out the Flag Chunk if appropriate ... */
300 if(writeChunk(fp
, flagheader
, cpFlag
, strlen(cpFlag
) + 1, progname
, filename
))
302 printf("%s: Error writing country flag string chunk %s.\n", progname
, filename
);
311 int main(int argc
, char **argv
)
313 int i
, j
, skipCountry
= 0;
317 iconv_t cd
= (iconv_t
)-1;
321 printf("%s: Wrong number of arguments\n", argv
[0]);
325 do_specific
= strcmp("--all", argv
[2]);
327 /* Check host OS locale. If it's UTF-8, use UTF-8 file names. Otherwise use Latin-1 names. */
328 name
= setlocale(LC_CTYPE
, "");
329 D(printf("System locale: %s\n", name
));
333 printf("%s: System locale is invalid\n",argv
[0]);
337 /* Use strstr() because for example on Linux this will be "en_US.UTF-8" while on MacOS it's just "UTF-8" */
338 if ((strstr(name
, "UTF-8")) || (strstr(name
, "utf8")))
340 cd
= iconv_open("UTF-8", "ISO-8859-1");
341 if (cd
== (iconv_t
)(-1))
343 printf("%s: Error converting character sets\n", argv
[0]);
348 for(j
=0; CountryArray
[j
].ca_Name
!= NULL
; j
++)
350 name
= CountryArray
[j
].ca_Name
;
352 if (cd
!= (iconv_t
)-1)
355 size_t inbytes
, outbytes
;
357 /* Convert country name to local character set */
358 inbytes
= strlen(name
) + 1;
359 outbytes
= sizeof(buffer
);
360 iconv(cd
, &name
, &inbytes
, &out
, &outbytes
);
366 /* locate the specified country */
367 for(i
=2; i
< argc
; i
++)
369 skipCountry
= strcmp(name
, argv
[i
]);
379 printf("Generating %s.country\n", name
);
381 strcpy(path
, argv
[1]);
383 strcat(path
, ".country");
384 doCountry(CountryArray
[j
].ca_Data
, argv
[0], path
);