Imported gammu 0.90.7
[gammu.git] / cfg / locale / locale.c
blob55be02be1ff969cd543519b56446091f0f2ed268
2 #include <stdio.h>
3 #include <string.h>
4 #include <wchar.h>
6 #include "../../cfg/config.h"
7 #include "../../common/misc/coding/coding.h"
8 #include "../../common/misc/cfg.h"
9 #include "../../common/misc/misc.h"
11 unsigned char line[1000];
12 int outputnum;
13 FILE *output;
14 INI_Section *cfg_info;
16 void WriteOutput(char *mystring)
18 unsigned char buffer[400];
20 EncodeUnicode(buffer,mystring,strlen(mystring));
21 fwrite(buffer,1,strlen(mystring)*2,output);
22 buffer[0] = 0x00;
23 buffer[1] = 0x0d;
24 buffer[2] = 0x00;
25 buffer[3] = 0x0a;
26 fwrite(buffer,1,4,output);
29 void ProcessSourceFile(char *filename)
31 int start,stop,num,i;
32 char *pdest;
33 FILE *file;
34 unsigned char buffer[10000],buffer2[500];
35 bool found;
37 printf("Processing source file %s\n",filename);
39 file = fopen(filename, "rb");
40 line[0]=0;
41 do {
42 num=fread(buffer, 1, 10000, file);
43 for (i=0;i<num;i++) {
44 switch (buffer[i]) {
45 case 10:
46 pdest = strstr( line, "printmsgerr" );
47 if (pdest != NULL) {
48 start = strlen(line) - strlen(pdest) + 1 + 11;
49 } else {
50 pdest = strstr( line, "printmsg" );
51 if (pdest != NULL) start = strlen(line) - strlen(pdest) + 1 + 8;
53 if (pdest != NULL) {
54 found = false;
55 stop = start + 2;
56 while (stop < ((int)strlen(line))) {
57 stop++;
58 if (line[stop-1] != '\\' && line[stop] == '"') {
59 found = true;
60 break;
63 if (found) {
64 sprintf(buffer2,"F%04i=%s",outputnum,line+start);
65 buffer2[stop-start+6+1] = 0;
66 WriteOutput(buffer2);
67 outputnum++;
70 line[0]=0;
71 break;
72 case 13:
73 break;
74 default:
75 line[strlen(line)+1] = 0;
76 line[strlen(line)] = buffer[i];
79 } while (num==10000);
80 fclose(file);
83 void RemoveDuplicatedStrings(char *filename)
85 int num2,num,number;
86 unsigned char buffer[500],buffer2[500],buff2[50];
87 INI_Entry *e,*ebackup,*e2;
88 bool duplicated;
90 printf("Removing duplicated strings from %s\n",filename);
92 EncodeUnicode (buff2, "common", 6);
94 cfg_info = INI_ReadFile(filename,true);
95 output = fopen(filename, "wb");
97 outputnum=0;
99 buffer[0] = 0xfe;
100 buffer[1] = 0xff;
101 fwrite(buffer,1,2,output);
102 sprintf(buffer,"# Localization file for Gammu (www.mwiacek.com) version %s",VERSION);
103 WriteOutput(buffer);
104 WriteOutput("");
105 WriteOutput("[common]");
107 e = INI_FindLastSectionEntry(cfg_info, buff2,true);
108 ebackup = e;
109 while (1) {
110 if (e == NULL) break;
111 num = -1;
112 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
113 if (strlen(buffer) == 5 && strncmp("F", buffer, 1) == 0) {
114 num = atoi(buffer+2);
116 if (num!=-1) {
117 duplicated = false;
118 e2 = ebackup;
119 number = 0;
120 while (1) {
121 if (e2 == NULL) break;
122 num2 = -1;
123 sprintf(buffer,"%s",DecodeUnicodeString(e2->EntryName));
124 if (strlen(buffer) == 5 && strncmp("F", buffer, 1) == 0) {
125 num2 = atoi(buffer+2);
126 number++;
128 if (num2 != -1 && num2 < num) {
129 if (mywstrncmp(e2->EntryValue, e->EntryValue, 0)) {
130 duplicated = true;
131 break;
134 e2 = e2->Prev;
135 if (number == num) break;
137 if (!duplicated) {
138 sprintf(buffer2,"F%04i=",outputnum);
139 EncodeUnicode(buffer,buffer2,6);
140 fwrite(buffer,1,12,output);
141 fwrite(e->EntryValue,1,UnicodeLength(e->EntryValue)*2,output);
142 WriteOutput("");
143 outputnum++;
146 e = e->Prev;
147 printf("*");
149 fclose(output);
150 printf("\n");
153 void ProcessLangFile(char *filename)
155 INI_Section *cfg_lang;
156 INI_Entry *e,*e_lang,*e2;
157 int num,num_lang;
158 char *retval_lang;
159 unsigned char buffer[10000],buffer2[10000],buff2[50];
161 printf("Processing file %s\n",filename);
163 cfg_lang = INI_ReadFile(filename,true);
164 output = fopen(filename, "wb");
166 buffer[0] = 0xfe;
167 buffer[1] = 0xff;
168 fwrite(buffer,1,2,output);
169 sprintf(buffer,"# Localization file for Gammu (www.mwiacek.com) version %s",VERSION);
170 WriteOutput(buffer);
171 WriteOutput("");
172 WriteOutput("[common]");
174 EncodeUnicode (buff2, "common", 6);
176 e2 = INI_FindLastSectionEntry(cfg_lang, buff2, true);
177 e = INI_FindLastSectionEntry(cfg_info, buff2, true);
178 while (1) {
179 if (e == NULL) break;
180 num = -1;
181 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
182 if (strlen(buffer) == 5 && strncmp("F", buffer, 1) == 0) {
183 num = atoi(buffer+2);
185 printf("*");
186 if (num!=-1) {
187 sprintf(buffer2,"F%04i=",num);
188 EncodeUnicode(buffer,buffer2,6);
189 fwrite(buffer,1,12,output);
190 fwrite(e->EntryValue,1,UnicodeLength(e->EntryValue)*2,output);
191 WriteOutput("");
192 e_lang = e2;
193 while (1) {
194 if (e_lang == NULL) break;
195 num_lang = -1;
196 sprintf(buffer,"%s",DecodeUnicodeString(e_lang->EntryName));
197 if (strlen(buffer) == 5 && strncmp("F", buffer, 1) == 0) {
198 num_lang = atoi(buffer+2);
200 if (num_lang!=-1) {
201 if (mywstrncmp(e_lang->EntryValue, e->EntryValue, 0)) {
202 sprintf(buffer2,"T%04i",num_lang);
203 EncodeUnicode(buffer,buffer2,6);
204 retval_lang = INI_GetValue(cfg_lang, buff2, buffer,true);
205 if (retval_lang != NULL) {
206 sprintf(buffer2,"T%04i=",num);
207 EncodeUnicode(buffer,buffer2,6);
208 fwrite(buffer,1,12,output);
209 fwrite(retval_lang,1,UnicodeLength(retval_lang)*2,output);
210 WriteOutput("");
212 break;
215 e_lang = e_lang->Prev;
218 e = e->Prev;
220 fclose(output);
221 printf("\n");
224 int main(int argc, char *argv[])
226 unsigned char buffer[400];
228 #ifdef WIN32
229 output = fopen("../../../../docs/docs/locale/gammu_us.txt", "wb");
230 #else
231 output = fopen("../../docs/docs/locale/gammu_us.txt", "wb");
232 #endif
233 buffer[0] = 0xfe;
234 buffer[1] = 0xff;
235 fwrite(buffer,1,2,output);
236 sprintf(buffer,"# Localization file for Gammu (www.mwiacek.com) version %s",VERSION);
237 WriteOutput(buffer);
238 WriteOutput("");
239 WriteOutput("[common]");
240 WriteOutput("F0001=\"No error.\"");
241 WriteOutput("F0002=\"Error opening device. Unknown/busy or no permissions.\"");
242 WriteOutput("F0003=\"Error setting device DTR or RTS\"");
243 WriteOutput("F0004=\"Error setting device speed. Maybe speed not supported.\"");
244 WriteOutput("F0005=\"Error writing device.\"");
245 WriteOutput("F0006=\"No response in specified timeout. Probably phone not connected.\"");
246 WriteOutput("F0007=\"Unknown response from phone. See readme.txt, how to report it.\"");
247 WriteOutput("F0008=\"Unknown connection type string. Check config file.\"");
248 WriteOutput("F0009=\"Unknown model type string. Check config file.\"");
249 WriteOutput("F0010=\"Some required functions not compiled for your OS. Please contact.\"");
250 WriteOutput("F0011=\"Function not supported by phone.\"");
251 WriteOutput("F0012=\"Entry is empty.\"");
252 WriteOutput("F0013=\"Unknown error.\"");
253 WriteOutput("F0014=\"Unknown error.\"");
254 WriteOutput("F0015=\"Security error. Maybe no PIN ?\"");
255 WriteOutput("F0016=\"Invalid location. Maybe too high ?\"");
256 WriteOutput("F0017=\"Function not implemented. Help required.\"");
257 WriteOutput("F0018=\"Can't open specified file. Read only ?\"");
258 WriteOutput("F0019=\"Memory full.\"");
259 WriteOutput("F0020=\"More memory required...\"");
260 WriteOutput("F0021=\"Permission to file/device required...\"");
261 WriteOutput("F0022=\"Family\"");
262 WriteOutput("F0023=\"VIP\"");
263 WriteOutput("F0024=\"Friends\"");
264 WriteOutput("F0025=\"Colleagues\"");
265 WriteOutput("F0026=\"Other\"");
266 WriteOutput("F0027=\"Inbox\"");
267 WriteOutput("F0028=\"Outbox\"");
268 WriteOutput("F0029=\"Empty SMSC number. Set in phone or use -smscnumber\"");
269 WriteOutput("F0030=\"You're inside phone menu (during editing ?). Leave it and try again.\"");
270 WriteOutput("F0031=\"Personal\"");
271 WriteOutput("F0032=\"Car\"");
272 WriteOutput("F0033=\"Headset\"");
273 WriteOutput("F0034=\"General\"");
274 WriteOutput("F0035=\"Silent\"");
275 WriteOutput("F0036=\"Meeting\"");
276 WriteOutput("F0037=\"Outdoor\"");
277 WriteOutput("F0038=\"Pager\"");
278 WriteOutput("F0039=\"Discreet\"");
279 WriteOutput("F0040=\"Loud\"");
280 WriteOutput("F0041=\"My style\"");
281 WriteOutput("F0042=\"Function is during writing. If want help, please contact with authors.\"");
282 WriteOutput("F0043=\"Error during reading device\"");
283 WriteOutput("F0044=\"Can't set parity on device\"");
284 WriteOutput("F0045=\"Phone is disabled and connected to charger\"");
285 WriteOutput("F0046=\"File format not supported by Gammu\"");
286 outputnum=47;
287 #ifdef WIN32
288 ProcessSourceFile("../../../../gammu/gammu.c");
289 #else
290 ProcessSourceFile("../../gammu/gammu.c");
291 #endif
292 fclose(output);
294 #ifdef WIN32
295 RemoveDuplicatedStrings("../../../../docs/docs/locale/gammu_us.txt");
296 cfg_info = INI_ReadFile("../../../../docs/docs/locale/gammu_us.txt",true);
298 ProcessLangFile("../../../../docs/docs/locale/gammu_pl.txt");
299 ProcessLangFile("../../../../docs/docs/locale/gammu_de.txt");
300 ProcessLangFile("../../../../docs/docs/locale/gammu_cs.txt");
301 #else
302 RemoveDuplicatedStrings("../../docs/docs/locale/gammu_us.txt");
303 cfg_info = INI_ReadFile("../../docs/docs/locale/gammu_us.txt",true);
305 ProcessLangFile("../../docs/docs/locale/gammu_pl.txt");
306 ProcessLangFile("../../docs/docs/locale/gammu_de.txt");
307 ProcessLangFile("../../docs/docs/locale/gammu_cs.txt");
308 #endif
309 printf("\n");
311 return (0);
314 /* How should editor hadle tabs in this file? Add editor commands here.
315 * vim: noexpandtab sw=8 ts=8 sts=8: