added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / locale / countries / makecountry / makecountry.c
blob7e7092b8ab93c5f1b0c57a023032ff0c682e7889
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Program that makes country files
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <libraries/locale.h>
11 #include <prefs/locale.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <aros/system.h>
17 #include <iconv.h>
19 #define EC(x)\
21 (x) = (((x) & 0xFF000000) >> 24)\
22 | (((x) & 0x00FF0000) >> 8)\
23 | (((x) & 0x0000FF00) << 8)\
24 | (((x) & 0x000000FF) << 24);\
27 struct CountryEntry
29 STRPTR ca_Name;
30 struct CountryPrefs *ca_Data;
33 extern struct CountryPrefs
34 andorraPrefs,
35 argentinaPrefs,
36 australiaPrefs,
37 belgiePrefs,
38 belgiquePrefs,
39 bosna_i_hercegovinaPrefs,
40 bulgarijaPrefs,
41 brasilPrefs,
42 canadaPrefs,
43 canada_francaisPrefs,
44 czech_republicPrefs,
45 danmarkPrefs,
46 deutschPrefs,
47 eirePrefs,
48 espanaPrefs,
49 francePrefs,
50 greatBritainPrefs,
51 hrvatskaPrefs,
52 iranPrefs,
53 irelandPrefs,
54 islandPrefs,
55 italiaPrefs,
56 jugoslavijaPrefs,
57 letzebuergPrefs,
58 liechtensteinPrefs,
59 lietuvaPrefs,
60 magyarorszagPrefs,
61 monacoPrefs,
62 nihonPrefs,
63 nederlandPrefs,
64 norgePrefs,
65 osterreichPrefs,
66 polskaPrefs,
67 portugalPrefs,
68 romaniaPrefs,
69 rossijaPrefs,
70 san_marinoPrefs,
71 schweizPrefs,
72 slovakiaPrefs,
73 slovenijaPrefs,
74 suissePrefs,
75 suomiPrefs,
76 sverigePrefs,
77 svizzeraPrefs,
78 turkiyePrefs,
79 ukrajinaPrefs,
80 united_kingdomPrefs,
81 united_statesPrefs,
82 vaticanoPrefs;
84 /* Please keep this in alphabetical order, ie the order of Latin 1 */
86 struct CountryEntry CountryArray[] =
88 { "andorra" , &andorraPrefs },
89 { "argentina" , &argentinaPrefs },
90 { "australia" , &australiaPrefs },
91 { "belgië" , &belgiePrefs },
92 { "belgique" , &belgiquePrefs },
93 { "bosna_i_hercegovina", &bosna_i_hercegovinaPrefs},
94 { "brasil" , &brasilPrefs },
95 { "bulgarija" , &bulgarijaPrefs },
96 { "canada" , &canadaPrefs },
97 { "canada_français" , &canada_francaisPrefs },
98 { "czech_republic" , &czech_republicPrefs },
99 { "danmark" , &danmarkPrefs },
100 { "deutschland" , &deutschPrefs },
101 { "éire" , &eirePrefs },
102 { "españa" , &espanaPrefs },
103 { "france" , &francePrefs },
104 { "great_britain" , &greatBritainPrefs },
105 { "hrvatska" , &hrvatskaPrefs },
106 { "iran" , &iranPrefs },
107 { "ireland" , &irelandPrefs },
108 { "ísland" , &islandPrefs },
109 { "italia" , &italiaPrefs },
110 { "jugoslavija" , &jugoslavijaPrefs },
111 { "liechtenstein" , &liechtensteinPrefs },
112 { "lëtzebuerg" , &letzebuergPrefs },
113 { "lietuva" , &lietuvaPrefs },
114 { "magyarország" , &magyarorszagPrefs },
115 { "monaco" , &monacoPrefs },
116 { "nihon" , &nihonPrefs },
117 { "nederland" , &nederlandPrefs },
118 { "norge" , &norgePrefs },
119 { "österreich" , &osterreichPrefs },
120 { "polska" , &polskaPrefs },
121 { "portugal" , &portugalPrefs },
122 { "românia" , &romaniaPrefs },
123 { "rossija" , &rossijaPrefs },
124 { "san_marino" , &san_marinoPrefs },
125 { "schweiz" , &schweizPrefs },
126 { "slovakia" , &slovakiaPrefs },
127 { "slovenija" , &slovenijaPrefs },
128 { "suisse" , &suissePrefs },
129 { "suomi" , &suomiPrefs },
130 { "sverige" , &sverigePrefs },
131 { "svizzera" , &svizzeraPrefs },
132 { "türkiye" , &turkiyePrefs },
133 { "ukrajina" , &ukrajinaPrefs },
134 { "united_kingdom" , &united_kingdomPrefs },
135 { "united_states" , &united_statesPrefs },
136 { "vaticano" , &vaticanoPrefs },
137 { NULL , NULL }
140 /* This is equivalent to the start of the catalog file.
141 It is a series of strings, so that the endianness is
142 correct either way
144 char preamble[] =
146 "FORM" "\x00\x00\x02\x12" "PREF"
148 "PRHD" "\x00\x00\x00\x06"
149 "\x00\x00\x00\x00\x00\x00"
151 "CTRY" "\x00\x00\x01\xF8"
155 int doCountry(struct CountryPrefs *cp, STRPTR progname, STRPTR filename)
157 FILE *fp;
159 fp = fopen(filename, "w");
160 if(fp == NULL)
162 printf("%s: Could not open file %s\n", progname, filename);
163 return (20);
166 /* Write the preamble...
167 FORM 0x00000212 PREF
168 PRHD 0x00000006
170 CTRY 0x000001F8
172 if(fwrite(preamble, 34, 1, fp) < 1)
174 printf("%s: Write error during preable of %s.\n", progname, filename);
175 fclose(fp);
176 return(20);
179 #if (AROS_BIG_ENDIAN == 0)
180 /* We have to convert the endianness of this data,
181 thankfully there are only two fields which this applies
184 EC(cp->cp_CountryCode);
185 EC(cp->cp_TelephoneCode);
186 #endif
188 if(fwrite(cp, sizeof(struct CountryPrefs), 1, fp) < 1)
190 printf("%s: Write error during data for %s.\n", progname, filename);
191 fclose(fp);
192 return(20);
195 fclose(fp);
196 return 0;
199 int main(int argc, char **argv)
201 int i,j,res = 0;
202 char buffer[1024];
203 char *inpos;
204 char *outpos;
205 size_t inbytes, outbytes;
206 iconv_t cd;
208 if(argc < 3)
210 printf("%s: Wrong number of arguments\n", argv[0]);
211 return(20);
214 cd = iconv_open("ISO-8859-1", "ISO-8859-1");
215 if(cd == (iconv_t)(-1))
217 printf("%s: Error converting character sets\n", argv[0]);
218 return(20);
221 for(i=2; i < argc; i++)
223 for(j=0; CountryArray[j].ca_Name != NULL; j++)
225 /* Convert country name to local character set */
226 inpos = CountryArray[j].ca_Name;
227 inbytes = strlen(inpos) + 1;
228 outpos = buffer;
229 outbytes = 1024;
230 iconv(cd, &inpos, &inbytes, &outpos, &outbytes);
232 res = strcmp(buffer, argv[i]);
233 if(res == 0)
235 strcpy(buffer, argv[1]);
236 strcat(buffer, argv[i]);
237 strcat(buffer, ".country");
238 doCountry(CountryArray[j].ca_Data, argv[0], buffer);
239 break;
241 #if 0
242 /* stegerg: does not work because of 'ö' in österreich */
243 /* If countryArray < argv[] don't bother searching */
244 else if(res > 0)
245 break;
246 #endif
249 if(res != 0)
251 printf("Unknown country %s\n", argv[i]);
252 //return(20);
255 return 0;