- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / devutils / roswebparser / roswebparser.c
1 /*
2 * This is a standalone rc langues to xml parser
3 * do not use windows or linux specfiy syntax or functions
4 * use only pure ansi C, this program is also runing on
5 * linux apachie webserver and being use in ReactOS website
6 *
7 * CopyRight 20/9-2006 by Magnus Olsen (magnus@greatlord.com)
8 * Licen GPL version 2.0
9 */
10
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <ctype.h>
16
17 #define true 1
18 #define false 0
19
20
21 int ansiCodePage(int codepage, unsigned char *inBuffer, unsigned char *outBuffer, int Lenght);
22
23 int paraser1(unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format, unsigned char *iso_type);
24
25 void find_str(unsigned char asc, unsigned char *buf, long *foundPos);
26 void find_str2(unsigned char *asc, unsigned char *buf, long *foundPos, unsigned char * output_resid, unsigned char *output_text );
27 void trim(unsigned char* buf);
28 void stringbugs(unsigned char *buf, int shift2);
29 void stringbugs2(unsigned char *buf, int shift2);
30
31 void ParserCMD1(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format);
32 void ParserCMD2(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format);
33 void ParserCMD3(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format);
34
35 void ParserComment(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format);
36 void ParserLang(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format);
37 void ParserString(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format);
38 void ParserDialog(unsigned char *text, long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format);
39 void DialogCMDBuild1(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text);
40 void DialogCMDBuild2(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text);
41 void DialogCMDBuild3(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text);
42 void ParserAccelerators(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format);
43 void ParserMenu(unsigned char *text, long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format);
44
45 /*
46 return -1 : No file found
47 return -2 : Fail open file
48 return -3 : Fail seek
49 return -4 : Fail get size
50 return -5 : Fail size of the file is 0 bytes
51 return -6 : Fail malloc memory
52 return -7 : Fail to read the file
53 return -8 : Fail to write to the file
54 return -9 : Fail to open write file
55 */
56
57 int main(int argc, char * argv[])
58 {
59 FILE * fp;
60 FILE * Outfp;
61 unsigned char * buffer;
62 unsigned char * output_text;
63 unsigned char * output_resid;
64 unsigned char * output_format;
65
66 long buf_size;
67 long buf_size_calc = 0;
68
69 if (argc!=4)
70 {
71 printf("Help\n");
72 printf("%s inputfile iso-type\n\n",argv[0]);
73 printf("example %s sv.rc 28591 sv.xml\n\n",argv[0]);
74 printf("Contry table\n");
75 printf("se (Swedish = Windows-28591 (Latin1 ISO-8859-1)\n");
76
77 return -1;
78 }
79
80
81 if ((fp = fopen(argv[1],"rb"))==NULL)
82 {
83 printf("Fail open file %s by %s\n",argv[1],argv[0]);
84 return -2;
85 }
86
87
88
89 fseek(fp,0,SEEK_END);
90 if (ferror(fp) !=0)
91 {
92 fclose(fp);
93 printf("Fail seek\n");
94 return -3;
95 }
96 buf_size = ftell(fp);
97 if (ferror(fp) !=0)
98 {
99 fclose(fp);
100 printf("Fail get size\n");
101 return -4;
102 }
103
104
105 /*
106 We make sure it is least 4 times + 2K biger
107 for we can grow around 2-3 times biger
108 so it better to make safe assume how
109 much memory we need
110 */
111
112 buf_size_calc = (buf_size*4) + 2048;
113
114 fseek(fp,0,SEEK_SET);
115 if (ferror(fp) !=0)
116 {
117 fclose(fp);
118 printf("Fail seek\n");
119 return -3;
120 }
121
122 if (buf_size==0)
123 {
124 fclose(fp);
125 printf("Fail size of the file is 0 bytes\n");
126 return -5;
127 }
128
129 buffer =(char *)malloc(buf_size_calc);
130 if (buffer == NULL)
131 {
132 fclose(fp);
133 printf("Fail malloc memory\n");
134 return -6;
135 }
136
137 output_text =(char *)malloc(buf_size_calc);
138 if (output_text == NULL)
139 {
140 free(buffer);
141 fclose(fp);
142 printf("Fail malloc memory\n");
143 return -6;
144 }
145
146 output_resid =(char *)malloc(buf_size_calc);
147 if (output_resid == NULL)
148 {
149 free(buffer);
150 free(output_text);
151 fclose(fp);
152 printf("Fail malloc memory\n");
153 return -6;
154 }
155
156 output_format =(char *)malloc(buf_size_calc);
157 if (output_format == NULL)
158 {
159 free(buffer);
160 free(output_text);
161 free(output_resid);
162 fclose(fp);
163 printf("Fail malloc memory\n");
164 return -6;
165 }
166
167 //fread(buffer,1,buf_size,fp);
168 fread(buffer,buf_size,1,fp);
169 if (ferror(fp) !=0)
170 {
171 fclose(fp);
172 printf("Fail to read the file\n");
173 return -7;
174 }
175 fclose(fp);
176
177 /* Now we can write our parser */
178
179 paraser1(buffer, buf_size, output_text, output_resid, output_format,"UTF-8");
180 // printf ("%s",output_format);
181
182 /* Now we convert to utf-8 */
183 memset(output_resid,0,buf_size_calc);
184 buf_size_calc = ansiCodePage(atoi(argv[2]), output_format, output_resid, strlen(output_format));
185
186 if ((Outfp = fopen(argv[3],"wb")) != NULL )
187 {
188 fwrite(output_resid,1,buf_size_calc,Outfp);
189 fclose(Outfp);
190 }
191
192
193
194
195 if(buffer!=NULL)
196 free(buffer);
197 if(output_text!=NULL)
198 free(output_text);
199 if(output_resid!=NULL)
200 free(output_resid);
201 if(output_format!=NULL)
202 free(output_format);
203
204
205 return 0;
206 }
207
208 int paraser1(unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format, unsigned char *iso_type)
209 {
210 unsigned char *row;
211 long foundPos=0;
212 long foundNextPos=0;
213 long row_size=0;
214 long pos=0;
215
216 memset(output_text,0,buf_size);
217 memset(output_resid,0,buf_size);
218 memset(output_format,0,buf_size);
219
220 sprintf(output_format,"<?xml version=\"1.0\" encoding=\"%s\"?>\n<resource>\n",iso_type);
221
222 row = output_text;
223 while(pos < buf_size)
224 {
225 foundPos=0;
226 foundNextPos=0;
227 row_size=0;
228
229 /* create a row string so we can easy scan it */
230 find_str('\n',&buf[pos],&foundPos);
231
232 if (foundPos !=0)
233 {
234 row_size = foundPos - 1;
235
236 /* found a new row */
237 strncpy(row, &buf[pos], row_size);
238 pos+=foundPos;
239 if (foundPos >=2)
240 row[row_size -1]=0;
241
242 }
243 else
244 {
245 row_size = buf_size - pos;
246
247 /* no new row found in the buffer */
248 strncpy(row, &buf[pos], buf_size - pos);
249 pos= buf_size;
250 }
251
252 trim(row);
253 foundPos=0;
254
255 /* Detect Basic command and send it to own paraser */
256 if (*row==0)
257 continue;
258
259 if (strncmp("/*",row,2)==0)
260 {
261 ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format);
262 continue;
263 }
264
265 if (strncmp("//",row,2)==0)
266 {
267 ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format);
268 continue;
269 }
270 if (strncmp("#",row,1)==0)
271 {
272 ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format);
273 continue;
274 }
275
276 stringbugs(row,true);
277
278 if (foundPos == 0)
279 {
280 find_str2 ("LANGUAGE ",row,&foundPos,output_resid,output_text);
281 if (foundPos != 0)
282 {
283 ParserLang("LANGUAGE", output_resid, output_text, output_format);
284 continue;
285 }
286 }
287
288 if (foundPos == 0)
289 {
290 find_str2 ("STRINGTABLE ",row,&foundPos,output_resid,output_text);
291 if (foundPos != 0)
292 {
293 ParserCMD3("STRINGTABLE", output_resid, output_text, output_format);
294 ParserString(&pos, buf, buf_size, output_text, output_resid, output_format);
295 continue;
296 }
297 }
298
299 if (foundPos == 0)
300 {
301 find_str2 (" DIALOGEX ",row,&foundPos,output_resid,output_text);
302 if (foundPos != 0)
303 {
304 ParserCMD2("DIALOGEX", output_resid, output_text, output_format);
305 ParserDialog("DIALOGEX",&pos, buf, buf_size, output_text, output_resid, output_format);
306 continue;
307 }
308 }
309
310 if (foundPos == 0)
311 {
312 find_str2 (" DIALOG ",row,&foundPos,output_resid,output_text);
313 if (foundPos != 0)
314 {
315 ParserCMD2("DIALOG", output_resid, output_text, output_format);
316 ParserDialog("DIALOG",&pos, buf, buf_size, output_text, output_resid, output_format);
317 continue;
318 }
319 }
320
321 if (foundPos == 0)
322 {
323 find_str2 (" ACCELERATORS\0",row,&foundPos,output_resid,output_text);
324 if (foundPos != 0)
325 {
326 ParserCMD1("ACCELERATORS", output_resid, output_text, output_format);
327 ParserAccelerators(&pos, buf, buf_size, output_text, output_resid, output_format);
328 continue;
329 }
330 }
331
332 if (foundPos == 0)
333 {
334 find_str2 (" MENU\0",row,&foundPos,output_resid,output_text);
335 if (foundPos != 0)
336 {
337 ParserCMD1("MENU", output_resid, output_text, output_format);
338 ParserMenu("MENU",&pos, buf, buf_size, output_text, output_resid, output_format);
339 continue;
340 }
341 }
342
343
344 } // end while
345 sprintf(output_format,"%s</resource>\n",output_format);
346 return false;
347 }
348
349 /*
350 ParserCMD
351 data
352 input : IDM_MDIFRAME MENU DISCARDABLE LANG LANG_TAG LANG_TAG
353 input : IDM_MDIFRAME MENU DISCARDABLE
354 input : IDM_MDIFRAME MENU
355 input : IDM_MDIFRAME ACCELERATORS DISCARDABLE LANG LANG_TAG LANG_TAG
356 input : IDM_MDIFRAME ACCELERATORS DISCARDABLE
357 input : IDM_MDIFRAME ACCELERATORS
358
359
360 output : <obj type="MENU" rc_name="ID">DISCARDABLE</obj>
361 output : <obj type="MENU" rc_name="ID">DISCARDABLE</obj>
362 output : <obj type="MENU" rc_name="ID"></obj>
363 output : <obj type="ACCELERATORS" rc_name="ID">DISCARDABLE</obj>
364 output : <obj type="ACCELERATORS" rc_name="ID">DISCARDABLE</obj>
365 output : <obj type="ACCELERATORS" rc_name="ID"></obj>
366
367 param : output_resid = rc_name ID
368 param : output_text = MENU DISCARDABLE LANG LANG_TAG LANG_TAG
369 param : text = type example MENU
370 param : output_format = xml data store buffer
371 */
372
373 void ParserCMD1(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format)
374 {
375 long le;
376
377 stringbugs(output_resid,false);
378 stringbugs(output_text,false);
379
380 le = strlen(text);
381
382 if (strlen(output_text) == le)
383 {
384 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\"></obj>\n",output_format,text,text,output_resid);
385 }
386 else if (output_text[le]==' ')
387 {
388 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\">DISCARDABLE</obj>\n",output_format,text,text,output_resid);
389 }
390
391 }
392
393 /*
394 ParserCMD2
395 data
396 input : IDM_MDIFRAME DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG
397 input : IDM_MDIFRAME DIALOG DISCARDABLE 15, 13, 210, 63
398 input : IDM_MDIFRAME DIALOGEX DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG
399 input : IDM_MDIFRAME DIALOGEX DISCARDABLE 15, 13, 210, 63
400
401
402 output : <obj type="DIALOG" rc_name="ID" top="15" left="13" right="210" bottom="63">DISCARDABLE</obj>
403 output : <obj type="DIALOG" rc_name="ID" top="15" left="13" right="210" bottom="63"></obj>
404 output : <obj type="DIALOGEX" rc_name="ID" top="15" left="13" right="210" bottom="63">DISCARDABLE</obj>
405 output : <obj type="DIALOGEX" rc_name="ID" top="15" left="13" right="210" bottom="63"></obj>
406
407
408 param : output_resid = rc_name ID
409 param : output_text = DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG
410 param : text = type example DIALOG
411 param : output_format = xml data store buffer
412
413 */
414
415 void ParserCMD2(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format)
416 {
417 long le;
418 long flag = 0;
419
420 stringbugs(output_resid,false);
421 stringbugs(output_text,false);
422
423 le=strlen(text);
424
425 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\" ",output_format,text,text,output_resid);
426
427 find_str2 (" DISCARDABLE ",output_text,&flag,output_resid,output_text);
428 trim(output_resid);
429 trim(output_text);
430 if (flag==0)
431 {
432 *output_resid='\0'; /* not in use futer */
433 flag=0; /* DISCARDABLE off */
434 sprintf(output_text,"%s",&output_text[le]);
435 trim(output_text);
436 }
437 else
438 {
439 *output_resid='\0'; /* not in use futer */
440 flag=1; /* DISCARDABLE on */
441 sprintf(output_text,"%s",&output_text[11]);
442 trim(output_text);
443 }
444
445 /* data is looking like this 0 1 2 3 now */
446
447 trim(output_resid);
448 trim(output_text);
449 find_str2 (" ",output_text,&flag,output_resid,output_text);
450 trim(output_resid);
451 trim(output_text);
452
453 sprintf(output_format,"%sleft=\"%s\" ",output_format,output_resid);
454
455 trim(output_resid);
456 trim(output_text);
457 find_str2 (" ",output_text,&flag,output_resid,output_text);
458 trim(output_resid);
459 trim(output_text);
460
461 sprintf(output_format,"%stop=\"%s\" ",output_format,output_resid);
462
463 trim(output_resid);
464 trim(output_text);
465 find_str2 (" ",output_text,&flag,output_resid,output_text);
466 trim(output_resid);
467 trim(output_text);
468
469 if (flag==0)
470 sprintf(output_format,"%swidth=\"%s\" height=\"%s\"></obj>\n",output_format,output_resid,output_text);
471 else
472 sprintf(output_format,"%swidth=\"%s\" height=\"%s\">DISCARDABLE</obj>\n",output_format,output_resid,output_text);
473 }
474
475 /*
476 ParserCMD3
477 data
478 input : STRINGTABLE DISCARDABLE LANG LANG_TAG LANG_TAG
479 input : STRINGTABLE DISCARDABLE LANG
480 input : STRINGTABLE LANG LANG_TAG LANG_TAG
481 input : STRINGTABLE
482
483
484 output : <obj type="STRINGTABLE">DISCARDABLE</obj>
485 output : <obj type="STRINGTABLE">DISCARDABLE</obj>
486 output : <obj type="STRINGTABLE"></obj>
487 output : <obj type="STRINGTABLE"></obj>
488
489
490 param : output_resid = empty
491 param : output_text = DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG
492 param : text = type example DIALOG
493 param : output_format = xml data store buffer
494
495 */
496 void ParserCMD3(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format)
497 {
498 long foundPos=0;
499
500 stringbugs(output_resid,false);
501 stringbugs(output_text,false);
502
503 find_str2 (" ",output_text,&foundPos,output_resid,output_text);
504 trim(output_resid);
505 trim(output_text);
506
507 if(strncmp("STRINGTABLE",output_text,11))
508 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\">DISCARDABLE</obj>\n",output_format,output_text,output_resid);
509 else
510 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\"></obj>\n",output_format,output_resid,output_text);
511
512 }
513 /*
514 ParserLang
515 data
516 input : LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
517 input : LANGUAGE LANG_ENGLISH SUBLANG_ENGLISH_US
518 output : <obj type="LANG" sublang="sub">lang</obj>
519 output : <obj type="LANG" sublang="sub">lang</obj>
520
521 param : output_resid = not in use
522 param : output_text = LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
523 param : text = type example LANGUAGE
524 param : output_format = xml data store buffer
525 */
526
527 void ParserLang(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format)
528 {
529 long foundPos=0;
530
531 stringbugs(output_resid,false);
532 stringbugs(output_text,false);
533
534 sprintf(output_text,"%s",&output_text[strlen(text)+1]);
535
536 /* split the lang into two string */
537 find_str2 (" ",output_text,&foundPos,output_resid,output_text);
538 trim(output_resid);
539 trim(output_text);
540 sprintf(output_format,"%s<group name=\"%s\">\n <obj type=\"%s\" sublang=\"%s\">%s</obj>\n</group>\n",output_format,text,text,output_text,output_resid);
541 }
542
543
544 /*
545 ParserComment
546 data
547 input : / * sadasdas asdasd asdas ... * /
548 output :<obj type=\"COMMENT\"><![CDATA[ sadasdas asdasd asdas ... ]]></obj>
549
550 input : / * sadasdas asdasd asdas ... * /
551 output :<obj type=\"COMMENT\"><![CDATA[ sadasdas asdasd asdas ... ]]></obj>
552
553 input : #if x
554 output :<obj type=\"COMMENT\"><![CDATA[#if x]]></obj>
555
556 input : // hi
557 output :<obj type=\"COMMENT\"><![CDATA[// hi]]></obj>
558
559 param : pos = current buf position
560 param : buf = read in buffer from file rc
561 param : buf_size = buf max size
562 param : output_text = using internal instead alloc more memory
563 param : output_resid = using internal instead alloc more memory
564 param : output_format = xml data store buffer
565 */
566
567 void ParserComment(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format)
568 {
569 long foundPos=0;
570 long foundNextPos=0;
571 long row_size=0;
572 unsigned char *row = output_text;
573
574
575 row_size = strlen(row);
576 if (strncmp("//",&row[0],2)==0)
577 {
578 sprintf(output_format,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s]]></obj>\n</group>\n",output_format,row);
579 return;
580 }
581 if (strncmp("#",&row[0],1)==0)
582 {
583 sprintf(output_format,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s]]></obj>\n</group>\n",output_format,row);
584 return;
585 }
586
587 for (foundNextPos=0;foundNextPos<row_size;foundNextPos++)
588 {
589 if (strncmp("*/",&row[foundNextPos],2)==0)
590 {
591 //*pos=*pos+foundNextPos+1;
592 //*pos=(*pos- (row_size+foundNextPos+2))+foundNextPos+2;
593 row[foundNextPos+2]='\0';
594 sprintf(output_format,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s]]></obj>\n</group>\n",output_format,row);
595 return;
596 }
597
598 }
599
600
601 sprintf(output_format,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s\n",output_format,output_text);
602
603 while(*pos < buf_size)
604 {
605 foundPos=0;
606 row_size=0;
607
608 /* create a row string so we can easy scan it */
609 find_str('\n',&buf[*pos],&foundPos);
610 if (foundPos !=0)
611 {
612 row_size = foundPos - 1;
613
614 /* found a new row */
615 strncpy(row, &buf[*pos], foundPos);
616 *pos+=foundPos;
617 if (foundPos >=2)
618 {
619 row[row_size -1]=0;
620 }
621
622 }
623 else
624 {
625 row_size = buf_size - *pos;
626
627 /* no new row found in the buffer */
628 strncpy(row, &buf[*pos], buf_size - *pos);
629 *pos= buf_size;
630 }
631
632 /* Search now after end of comment */
633 row_size=strlen(row);
634 for (foundNextPos=0;foundNextPos<row_size;foundNextPos++)
635 {
636 if (strncmp("*/",&row[foundNextPos],2)==0)
637 {
638 row_size=row_size - (foundNextPos+2);
639 *pos-=row_size;
640 row[foundNextPos+2]='\0';
641 sprintf(output_format,"%s%s]]></obj>\n</group>\n",output_format,row);
642 return;
643 }
644 }
645 sprintf(output_format,"%s%s\n",output_format,row);
646 }
647
648 }
649
650 /*
651 ParserAccelerators
652 data
653 input : BEGIN
654 input : "^A", CMD_SELECT_ALL
655 input : END
656
657 output : <obj type="ACCELERATORS" command="BEGIN" />
658 output : <obj type="ACCELERATORS" rc_name="CMD_SEARCH"><![CDATA[^F]]></obj>
659 output : <obj type="ACCELERATORS" command="END" />
660
661 param : pos = current buf position
662 param : buf = read in buffer from file rc
663 param : buf_size = buf max size
664 param : output_text = using internal instead alloc more memory
665 param : output_resid = using internal instead alloc more memory
666 param : output_format = xml data store buffer
667 */
668 void ParserAccelerators(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format)
669 {
670 long foundPos=0;
671 long foundNextPos=0;
672 long row_size=0;
673 char *row = output_text;
674 int start=false;
675 long le;
676
677 while(*pos < buf_size)
678 {
679 foundPos=0;
680 row_size=0;
681
682 /* create a row string so we can easy scan it */
683 find_str('\n',&buf[*pos],&foundPos);
684 if (foundPos !=0)
685 {
686 row_size = foundPos - 1;
687
688 /* found a new row */
689 strncpy(row, &buf[*pos], foundPos);
690 *pos+=foundPos;
691 if (foundPos >=2)
692 {
693 row[row_size -1]=0;
694 }
695
696 }
697 else
698 {
699 row_size = buf_size - *pos;
700
701 /* no new row found in the buffer */
702 strncpy(row, &buf[*pos], buf_size - *pos);
703 *pos= buf_size;
704 }
705
706 stringbugs(row,true);
707 if (start == false)
708 {
709 if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0))
710 {
711 start=true;
712 sprintf(output_format,"%s <obj type=\"ACCELERATORS\" command=\"BEGIN\" />\n",output_format);
713
714 }
715 continue;
716 }
717
718 if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0))
719 {
720 sprintf(output_format,"%s <obj type=\"ACCELERATORS\" command=\"END\" />\n</group>\n",output_format);
721
722 *output_resid = '\0';
723 break;
724 }
725
726 foundPos=0;
727 foundNextPos=0;
728 find_str('"',row,&foundPos);
729 find_str('"',&row[foundPos],&foundNextPos);
730
731 if ((foundPos!=0) && (foundNextPos!=0))
732 {
733
734 sprintf(output_format,"%s <obj type=\"KEY\" rc_name=\"",output_format);
735 le = strlen(output_format);
736 sprintf(output_format,"%s%s",output_format,&row[foundNextPos+foundPos]);
737 trim(&output_format[le]);
738 row[foundNextPos+foundPos]='\0';
739 row[foundPos-1]=' ';
740 foundPos=0;
741 find_str('"',row,&foundPos);
742 if (foundPos!=0)
743 {
744 row[foundPos-1]=' ';
745 }
746
747 trim(row);
748 sprintf(output_format,"%s\"><![CDATA[%s]]></obj>\n",output_format,row);
749 }
750 }
751 }
752
753 /*
754 ParserString
755 data
756 input : BEGIN
757 input : IDS_HINT_BLANK "text"
758 input : END
759
760 output : <obj type="STRINGTABLE" command="BEGIN" />
761 output : <obj type="STRING" rc_name="rc_id">text</obj>
762 output : <obj type="STRINGTABLE" command="END" />
763
764 param : pos = current buf position
765 param : buf = read in buffer from file rc
766 param : buf_size = buf max size
767 param : output_text = using internal instead alloc more memory
768 param : output_resid = using internal instead alloc more memory
769 param : output_format = xml data store buffer
770 */
771 void ParserString(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format)
772 {
773 long foundPos=0;
774 long row_size=0;
775 unsigned char *row = output_text;
776 int start=false;
777
778 while(*pos < buf_size)
779 {
780 foundPos=0;
781 row_size=0;
782
783 /* create a row string so we can easy scan it */
784 find_str('\n',&buf[*pos],&foundPos);
785
786 if (foundPos !=0)
787 {
788 row_size = foundPos - 1;
789
790 /* found a new row */
791 strncpy(row, &buf[*pos], foundPos);
792 *pos+=foundPos;
793 if (foundPos >=2)
794 {
795 row[row_size -1]=0;
796 }
797
798 }
799 else
800 {
801 row_size = buf_size - *pos;
802
803 /* no new row found in the buffer */
804 strncpy(row, &buf[*pos], buf_size - *pos);
805 *pos= buf_size;
806 }
807
808 stringbugs(row,true);
809
810
811 if (start == false)
812 {
813 if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0))
814 {
815
816 start=true;
817 sprintf(output_format,"%s <obj type=\"STRINGTABLE\" command=\"BEGIN\" />\n",output_format);
818 }
819 continue;
820 }
821
822 if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0))
823 {
824 sprintf(output_format,"%s <obj type=\"STRINGTABLE\" command=\"END\" />\n</group>\n",output_format);
825
826 *output_resid = '\0';
827 break;
828 }
829
830
831
832 /* the split code here */
833 foundPos=0;
834 find_str2 (" ",row,&foundPos,output_resid,output_text);
835
836 if (foundPos != 0)
837 {
838 trim(output_text);
839 trim(output_resid);
840
841 if (*output_resid!='\0')
842 sprintf(output_format,"%s <obj type=\"STRING\" rc_name=\"%s\"><![CDATA[%s]]></obj>\n",output_format,output_resid,output_text);
843 else
844 sprintf(output_format,"%s <obj type=\"STRING\" rc_name=\"%s\"></obj>\n",output_format,output_resid);
845 }
846
847 }
848 }
849
850 /*
851 ParserDialog
852 data
853
854 input : BEGIN
855 output : <obj type="DIALOG" command="BEGIN" />
856 output : <obj type="DIALOGEX" command="BEGIN" />
857
858 input : END
859 output : <obj type="END" command="BEGIN" />
860 output : <obj type="END" command="BEGIN" />
861
862 input : {
863 output : <obj type="DIALOG" command="BEGIN" />
864 output : <obj type="DIALOGEX" command="BEGIN" />
865
866 input : }
867 output : <obj type="END" command="BEGIN" />
868 output : <obj type="END" command="BEGIN" />
869
870 input : FONT 8, "MS Shell Dlg"
871 output : <obj type="FONT" size="8" name="MS Shell Dlg"></obj>
872
873 input : FONT 8, "MS Shell Dlg", 0, 0, 0x1
874 output : <obj type="FONT" size="8" name="MS Shell Dlg">0 0 0x1</obj>
875
876 input : CONTROL "",101,"Static",SS_SIMPLE | SS_NOPREFIX,3,6,150,10
877 output : <obj type="CONTROL" rc_name="IDC_ICON_ALIGN_1" prop="Button" style="BS_OWNERDRAW |BS_BOTTOM | WS_TABSTOP" top="57" left="25" right="46" bottom="44"><![CDATA[left/top right]]></obj>
878
879
880 Builder1
881 input : DEFPUSHBUTTON "&OK",1,158,6,47,14 xx
882 input : PUSHBUTTON "&Cancel",2,158,23,47,14 xx
883 input : LTEXT "&Tooltip Text:",IDC_LABEL1,7,44,40,8 xx
884 input : GROUPBOX "&Display Mode",IDC_LABEL4,7,96,157,28 xx
885 input : ICON "",IDC_PICTURE,173,101,21,20 xx
886
887 input : EDITTEXT 201,3,29,134,12,ES_AUTOHSCROLL
888 input : LISTBOX IDC_LIST, 4, 16, 104, 46, WS_TABSTOP
889 input : COMBOBOX ID_EOLN,54,18,156,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
890
891 output : <obj type="COMBOBOX" rc_name="ID_ENCODING" top="54" left="0" right="156" bottom="80" style="CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP"></obj>
892 output : <obj type="COMBOBOX" rc_name="ID_ENCODING" top="54" left="0" right="156" bottom="80"></obj>
893
894 output : <obj type="GROUPBOX" rc_name="IDC_LABEL4" top="7" left="96" right="157" bottom="28" style="CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP"><![CDATA[&Display Mode]]></obj>
895 output : <obj type="GROUPBOX" rc_name="IDC_LABEL4" top="7" left="96" right="157" bottom="28"><![CDATA[&Display Mode]]></obj>
896
897 builder2
898 input : CAPTION "Execute"
899 input : EXSTYLE WS_EX_APPWINDOW
900 input : STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
901
902 output : <obj type="STYLE">DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU</obj>
903
904 param : pos = current buf position
905 param : buf = read in buffer from file rc
906 param : buf_size = buf max size
907 param : output_text = using internal instead alloc more memory
908 param : output_resid = using internal instead alloc more memory
909 param : output_format = xml data store buffer
910 */
911 void ParserDialog(unsigned char *text, long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format)
912 {
913 long foundPos=0;
914 long foundNextPos=0;
915 long row_size=0;
916 unsigned char *row = output_text;
917 long commandfound=0;
918 long le;
919
920 *output_resid='\0';
921 le=0;
922
923 while(*pos < buf_size)
924 {
925 foundPos=0;
926 row_size=0;
927
928 /* create a row string so we can easy scan it */
929 find_str('\n',&buf[*pos],&foundPos);
930 if (foundPos !=0)
931 {
932 row_size = foundPos - 1;
933
934 /* found a new row */
935 strncpy(row, &buf[*pos], foundPos);
936 *pos+=foundPos;
937 if (foundPos >=2)
938 {
939 row[row_size -1]=0;
940 }
941
942 }
943 else
944 {
945 row_size = buf_size - *pos;
946
947 /* no new row found in the buffer */
948 strncpy(row, &buf[*pos], buf_size - *pos);
949 *pos= buf_size;
950 }
951
952 //stringbugs(row,true);
953 trim(row);
954
955 if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0))
956 commandfound=1;
957 if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0))
958 commandfound=2;
959
960 if (strncmp("STYLE ",row,6)==0)
961 commandfound=3;
962 if (strncmp("CAPTION ",row,8)==0)
963 commandfound=3;
964 if (strncmp("FONT ",row,5)==0)
965 commandfound=3;
966 if (strncmp("CONTROL ",row,8)==0)
967 commandfound=3;
968 if (strncmp("EDITTEXT ",row,9)==0)
969 commandfound=3;
970 if (strncmp("DEFPUSHBUTTON ",row,14)==0)
971 commandfound=3;
972 if (strncmp("PUSHBUTTON ",row,11)==0)
973 commandfound=3;
974 if (strncmp("LTEXT ",row,6)==0)
975 commandfound=3;
976 if (strncmp("GROUPBOX ",row,9)==0)
977 commandfound=3;
978 if (strncmp("ICON ",row,5)==0)
979 commandfound=3;
980 if (strncmp("EXSTYLE ",row,8)==0)
981 commandfound=3;
982 if (strncmp(row,"LISTBOX ",8)==0)
983 commandfound=3;
984 if (strncmp(row,"COMBOBOX ",9)==0)
985 commandfound=3;
986
987 if ((*output_resid!=0) && (commandfound!=0))
988 {
989 /* Builder 1*/
990 if (strncmp(output_resid,"LTEXT ",6)==0)
991 DialogCMDBuild1(output_resid, output_format, 5, "LTEXT");
992 if (strncmp(output_resid,"GROUPBOX ",9)==0)
993 DialogCMDBuild1(output_resid, output_format, 8, "GROUPBOX");
994 if (strncmp(output_resid,"DEFPUSHBUTTON ",14)==0)
995 DialogCMDBuild1(output_resid, output_format, 13, "DEFPUSHBUTTON");
996 if (strncmp(output_resid,"PUSHBUTTON ",11)==0)
997 DialogCMDBuild1(output_resid, output_format, 10, "PUSHBUTTON");
998 if (strncmp("ICON ",output_resid,5)==0)
999 DialogCMDBuild1(output_resid, output_format, 4, "ICON");
1000 if (strncmp("EDITTEXT ",output_resid,9)==0)
1001 DialogCMDBuild1(output_resid, output_format, 8, "EDITTEXT");
1002 if (strncmp("LISTBOX ",output_resid,8)==0)
1003 DialogCMDBuild1(output_resid, output_format, 7, "LISTBOX");
1004 if (strncmp("COMBOBOX ",output_resid,9)==0)
1005 DialogCMDBuild1(output_resid, output_format, 8, "COMBOBOX");
1006
1007 /* Builder 2*/
1008 if (strncmp("STYLE ",output_resid,6)==0)
1009 DialogCMDBuild2(output_resid, output_format, 5, "STYLE");
1010 if (strncmp("EXSTYLE ",output_resid,8)==0)
1011 DialogCMDBuild2(output_resid, output_format, 7, "EXSTYLE");
1012 if (strncmp("CAPTION ",output_resid,8)==0)
1013 DialogCMDBuild2(output_resid, output_format, 7, "CAPTION");
1014 if (strncmp("CONTROL ",output_resid,8)==0)
1015 DialogCMDBuild3(output_resid, output_format, 7, "CONTROL");
1016
1017 /* no builder */
1018 if (strncmp(output_resid,"FONT ",5)==0)
1019 {
1020 stringbugs(output_resid,true);
1021 /* FONT */
1022 sprintf(output_resid,"%s",&output_resid[5]);
1023 trim(output_resid);
1024 sprintf(output_format,"%s <obj type=\"FONT\" size=\"",output_format);
1025 le = strlen(output_format);
1026 sprintf(output_format,"%s%s",output_format,output_resid);
1027
1028 foundPos=0;
1029 find_str('\"',output_resid,&foundPos);
1030 output_format[le+foundPos-1]='\0';
1031 trim(&output_format[le]);
1032 sprintf(output_format,"%s\" name=",output_format);
1033 le = strlen(output_format);
1034 sprintf(output_format,"%s%s",output_format,&output_resid[foundPos-1]);
1035
1036 foundNextPos=0;
1037 find_str('\"',&output_resid[foundPos],&foundNextPos);
1038 output_format[le+foundPos+foundNextPos-1]='\0';
1039 trim(&output_format[le+foundPos]);
1040 if (output_resid[foundPos+foundNextPos]=='\0')
1041 {
1042 sprintf(output_format,"%s></obj>\n",output_format);
1043 }
1044 else
1045 {
1046 sprintf(output_format,"%s\">%s</obj>\n",output_format,&output_resid[foundPos]);
1047 }
1048
1049 *output_resid=0;
1050 }
1051
1052 *output_resid='\0';
1053 }
1054
1055 if (commandfound==1)
1056 {
1057 sprintf(output_format,"%s <obj type=\"%s\" command=\"BEGIN\" />\n",output_format,text);
1058 }
1059 if (commandfound==2)
1060 {
1061 sprintf(output_format,"%s <obj type=\"%s\" command=\"END\" />\n</group>\n",output_format,text);
1062 break;
1063 }
1064
1065 sprintf(output_resid,"%s%s",output_resid,row);
1066 commandfound=0;
1067 }
1068
1069 }
1070 //////////////////////////
1071 /*
1072 ParserDialog
1073 data
1074
1075 input : BEGIN
1076 output : <obj type="DIALOG" command="BEGIN" />
1077 output : <obj type="DIALOGEX" command="BEGIN" />
1078
1079 input : END
1080 output : <obj type="END" command="BEGIN" />
1081 output : <obj type="END" command="BEGIN" />
1082
1083 input : {
1084 output : <obj type="DIALOG" command="BEGIN" />
1085 output : <obj type="DIALOGEX" command="BEGIN" />
1086
1087 input : }
1088 output : <obj type="END" command="BEGIN" />
1089 output : <obj type="END" command="BEGIN" />
1090
1091 param : pos = current buf position
1092 param : buf = read in buffer from file rc
1093 param : buf_size = buf max size
1094 param : output_text = using internal instead alloc more memory
1095 param : output_resid = using internal instead alloc more memory
1096 param : output_format = xml data store buffer
1097 */
1098 void ParserMenu(unsigned char *text, long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format)
1099 {
1100 long foundPos=0;
1101 long foundNextPos=0;
1102 long row_size=0;
1103 unsigned char *row = output_text;
1104 long commandfound=0;
1105 long le;
1106 long count=0;
1107
1108 *output_resid='\0';
1109 le=0;
1110
1111 while(*pos < buf_size)
1112 {
1113 foundPos=0;
1114 row_size=0;
1115
1116 /* create a row string so we can easy scan it */
1117 find_str('\n',&buf[*pos],&foundPos);
1118 if (foundPos !=0)
1119 {
1120 row_size = foundPos - 1;
1121
1122 /* found a new row */
1123 strncpy(row, &buf[*pos], foundPos);
1124 *pos+=foundPos;
1125 if (foundPos >=2)
1126 {
1127 row[row_size -1]=0;
1128 }
1129
1130 }
1131 else
1132 {
1133 row_size = buf_size - *pos;
1134
1135 /* no new row found in the buffer */
1136 strncpy(row, &buf[*pos], buf_size - *pos);
1137 *pos= buf_size;
1138 }
1139
1140 //stringbugs(row,true);
1141 stringbugs2(row,true);
1142
1143 if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0))
1144 commandfound=1;
1145 if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0))
1146 commandfound=2;
1147
1148 if (strncmp("POPUP ",row,6)==0)
1149 commandfound=3;
1150 if (strncmp("MENUITEM ",row,8)==0)
1151 commandfound=3;
1152
1153
1154 if ((*output_resid!=0) && (commandfound!=0))
1155 {
1156 if (strncmp(output_resid,"POPUP ",6)==0)
1157 {
1158 sprintf(output_resid,"%s",&output_resid[5]);
1159 trim(output_resid);
1160 sprintf(output_format,"%s<obj type=\"POPUP\"><![CDATA[%s]]></obj>\n",output_format,output_resid);
1161 *output_resid='\0';
1162 }
1163
1164 if (strncmp(output_resid,"MENUITEM ",9)==0)
1165 {
1166 sprintf(output_resid,"%s",&output_resid[8]);
1167 trim(output_resid);
1168 if (strcmp(output_resid,"SEPARATOR")==0)
1169 {
1170 sprintf(output_format,"%s<obj type=\"MENUITEMSEPERATOR\"></obj>\n",output_format);
1171 *output_resid='\0';
1172 }
1173 else
1174 {
1175 foundPos=0;
1176 foundNextPos=0;
1177 find_str('"',output_resid,&foundPos);
1178 find_str('"',&output_resid[foundPos],&foundNextPos);
1179
1180 stringbugs(&output_resid[foundPos+foundNextPos],true);
1181
1182 if ((foundPos+foundNextPos)==0)
1183 {
1184 sprintf(output_format,"%s<obj type=\"MENUITEM\" rc_name=\"%s\"></obj>\n",output_format,&output_resid[foundPos+foundNextPos]);
1185 }
1186 else
1187 {
1188 sprintf(output_format,"%s<obj type=\"MENUITEM\" rc_name=\"%s\">",output_format,&output_resid[foundPos+foundNextPos]);
1189
1190 output_resid[foundPos+foundNextPos]='\0';
1191 trim(output_resid);
1192
1193 sprintf(output_format,"%s<![CDATA[%s]]></obj>\n",output_format,output_resid);
1194 }
1195
1196
1197
1198 *output_resid='\0';
1199 }
1200 }
1201
1202
1203
1204 *output_resid='\0';
1205 }
1206
1207 if (commandfound==1)
1208 {
1209 count++;
1210 if (count==1)
1211 sprintf(output_format,"%s<obj type=\"%s\" command=\"BEGIN\" />\n",output_format,text);
1212 else
1213 sprintf(output_format,"%s<obj type=\"POPUP\" command=\"BEGIN\" />\n",output_format);
1214
1215 *output_resid='\0';
1216 }
1217 if (commandfound==2)
1218 {
1219 count--;
1220 *output_resid='\0';
1221
1222 if (count<1)
1223 sprintf(output_format,"%s<obj type=\"%s\" command=\"END\" />\n",output_format,text);
1224 else
1225 sprintf(output_format,"%s<obj type=\"POPUP\" command=\"END\" />\n",output_format);
1226
1227 if (count<1)
1228 {
1229 sprintf(output_format,"%s</group>\n",output_format);
1230 break;
1231 }
1232 }
1233
1234 sprintf(output_resid,"%s%s",output_resid,row);
1235 commandfound=0;
1236 }
1237
1238 }
1239
1240 void stringbugs(unsigned char *buf, int shift2)
1241 {
1242 long foundPos=0;
1243 long foundNextPos=0;
1244 long t=0;
1245
1246 /* remove , */
1247 if (shift2== false)
1248 {
1249 for (t=0;t<strlen(buf);t++)
1250 {
1251 if (foundPos==0)
1252 {
1253 if (strncmp(",",&buf[t],1)==0)
1254 {
1255 buf[t]=' ';
1256 }
1257
1258 if (strncmp("\"",&buf[t],1)==0)
1259 {
1260 buf[t]=' ';
1261 }
1262
1263 if (strncmp("/*",&buf[t],2)==0)
1264 {
1265 foundPos=t;
1266 buf[t]=' ';
1267 buf[t+1]=' ';
1268 }
1269 }
1270 else
1271 {
1272 if (strncmp("*/",&buf[t],2)==0)
1273 {
1274 buf[t]=' ';
1275 buf[t+1]=' ';
1276 foundPos=0;
1277 }
1278 else
1279 {
1280 buf[t]=' ';
1281 }
1282 }
1283 }
1284 }
1285 else
1286 {
1287 /* shift */
1288 for (t=0;t<strlen(buf);t++)
1289 {
1290 if ((foundPos==0) && (foundNextPos==0))
1291 {
1292 if (strncmp(",",&buf[t],1)==0)
1293 {
1294 buf[t]=' ';
1295 }
1296
1297 if (strncmp("\"",&buf[t],1)==0)
1298 {
1299 foundNextPos=t;
1300 }
1301
1302 if (strncmp("/*",&buf[t],2)==0)
1303 {
1304 foundPos=t;
1305 buf[t]=' ';
1306 buf[t+1]=' ';
1307 }
1308 }
1309 else
1310 {
1311 if (foundPos!=0)
1312 {
1313 if (strncmp("*/",&buf[t],2)==0)
1314 {
1315 buf[t]=' ';
1316 buf[t+1]=' ';
1317 foundPos=0;
1318 }
1319 else
1320 {
1321 buf[t]=' ';
1322 }
1323 }
1324 if (foundNextPos!=0)
1325 {
1326 if (strncmp("\"",&buf[t],1)==0)
1327 {
1328 foundNextPos=0;
1329 }
1330 }
1331 }
1332 }
1333 }
1334
1335 trim(buf);
1336 /* have remove all wrong syntax */
1337 }
1338
1339 void stringbugs2(unsigned char *buf, int shift2)
1340 {
1341 long foundPos=0;
1342 long foundNextPos=0;
1343 long t=0;
1344
1345 /* remove , */
1346 if (shift2== false)
1347 {
1348 for (t=0;t<strlen(buf);t++)
1349 {
1350 if (foundPos==0)
1351 {
1352
1353 if (strncmp("\"",&buf[t],1)==0)
1354 {
1355 buf[t]=' ';
1356 }
1357
1358 if (strncmp("/*",&buf[t],2)==0)
1359 {
1360 foundPos=t;
1361 buf[t]=' ';
1362 buf[t+1]=' ';
1363 }
1364 }
1365 else
1366 {
1367 if (strncmp("*/",&buf[t],2)==0)
1368 {
1369 buf[t]=' ';
1370 buf[t+1]=' ';
1371 foundPos=0;
1372 }
1373 else
1374 {
1375 buf[t]=' ';
1376 }
1377 }
1378 }
1379 }
1380 else
1381 {
1382 /* shift */
1383 for (t=0;t<strlen(buf);t++)
1384 {
1385 if ((foundPos==0) && (foundNextPos==0))
1386 {
1387
1388 if (strncmp("\"",&buf[t],1)==0)
1389 {
1390 foundNextPos=t;
1391 }
1392
1393 if (strncmp("/*",&buf[t],2)==0)
1394 {
1395 foundPos=t;
1396 buf[t]=' ';
1397 buf[t+1]=' ';
1398 }
1399 }
1400 else
1401 {
1402 if (foundPos!=0)
1403 {
1404 if (strncmp("*/",&buf[t],2)==0)
1405 {
1406 buf[t]=' ';
1407 buf[t+1]=' ';
1408 foundPos=0;
1409 }
1410 else
1411 {
1412 buf[t]=' ';
1413 }
1414 }
1415 if (foundNextPos!=0)
1416 {
1417 if (strncmp("\"",&buf[t],1)==0)
1418 {
1419 foundNextPos=0;
1420 }
1421 }
1422 }
1423 }
1424 }
1425
1426 trim(buf);
1427 /* have remove all wrong syntax */
1428 }
1429
1430
1431
1432 void trim(unsigned char* buf)
1433 {
1434 size_t le;
1435
1436 if (buf==NULL)
1437 return;
1438 if (*buf==0)
1439 return;
1440
1441 le=strlen(buf);
1442
1443
1444 while(le>0)
1445 {
1446
1447 if (isspace(buf[le-1])!=0)
1448 {
1449 buf[le-1]=0;
1450 le=strlen(buf);
1451 }
1452 else
1453 {
1454 break;
1455 }
1456 }
1457
1458 le=strlen(buf);
1459 while(le>0)
1460 {
1461 if (isspace(buf[0])!=0)
1462 {
1463 strncpy(&buf[0],&buf[1],le-1);
1464 buf[le-1]=0;
1465 le=strlen(buf);
1466 }
1467 else
1468 {
1469 break;
1470 }
1471 }
1472 }
1473 void find_str(unsigned char asc,unsigned char *buf, long *foundPos)
1474 {
1475 int t;
1476 size_t le;
1477
1478 le=strlen(buf);
1479
1480 for (t=0;t<le;t++)
1481 {
1482 if (buf[t]==asc)
1483 {
1484 *foundPos = *foundPos+t+1;
1485 break ;
1486 }
1487 }
1488
1489 /* for end of line the \ is a special case */
1490 if ((asc == '\n') && (foundPos!=0) && (buf[t-2]=='\\'))
1491 {
1492 long extra=t+1;
1493
1494 find_str(asc, &buf[extra], foundPos);
1495 }
1496
1497 }
1498
1499 void find_str2(unsigned char *asc, unsigned char *buf, long *foundPos,
1500 unsigned char * output_resid, unsigned char *output_text)
1501 {
1502 int t=0;
1503 size_t le;
1504 size_t lec;
1505
1506 le=strlen(buf);
1507 lec=strlen(asc);
1508
1509 if ((lec==0) || (le==0))
1510 {
1511 return;
1512 }
1513
1514 for (t=0;t<le;t++)
1515 {
1516 if (strncmp(&buf[t],asc,lec)==0)
1517 {
1518 long softfoundPos=0;
1519
1520 *foundPos = *foundPos+t+lec;
1521 softfoundPos = *foundPos;
1522
1523 strncpy(output_resid, &buf[0], t);
1524 output_resid[t]=0;
1525
1526 strncpy(output_text, &buf[t], le-t);
1527 output_text[ le-t ]=0;
1528
1529 break ;
1530 }
1531 }
1532 }
1533
1534
1535 void DialogCMDBuild1(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text)
1536 {
1537
1538
1539 unsigned char extra[1000];
1540 long foundPos=0;
1541 long foundNextPos=0;
1542 long le;
1543 long size;
1544
1545 stringbugs(output_resid,true);
1546 sprintf(output_resid,"%s",&output_resid[pos]);
1547 trim(output_resid);
1548
1549 find_str('"',output_resid,&foundPos);
1550 find_str('"',&output_resid[foundPos],&foundNextPos);
1551
1552 if ((foundPos!=0) && (foundPos!=0))
1553 {
1554 strcpy(extra,&output_resid[foundPos+foundNextPos]);
1555 trim(extra);
1556
1557 output_resid[foundPos+foundNextPos]='\0';
1558 trim(output_resid);
1559 }
1560 else
1561 {
1562 strcpy(extra,output_resid);
1563 *output_resid='\0';
1564 }
1565 // \0
1566 sprintf(output_format,"%s <obj type=\"%s\" rc_name=\"%s",output_format,text,extra);
1567 foundPos=0;
1568 find_str(' ',extra,&foundPos);
1569 le = (strlen(output_format) - strlen(extra))+foundPos-1;
1570 output_format[le]='\0';
1571 sprintf(extra,"%s",&extra[foundPos]);
1572 trim(extra);
1573
1574 /* top */
1575 // \0
1576 sprintf(output_format,"%s\" left=\"%s",output_format,extra);
1577 foundPos=0;
1578 find_str(' ',extra,&foundPos);
1579 le = (strlen(output_format) - strlen(extra))+foundPos-1;
1580 output_format[le]='\0';
1581 sprintf(extra,"%s",&extra[foundPos]);
1582 trim(extra);
1583
1584 /* left */
1585 // \0
1586 sprintf(output_format,"%s\" top=\"%s",output_format,extra);
1587 foundPos=0;
1588 find_str(' ',extra,&foundPos);
1589 le = (strlen(output_format) - strlen(extra))+foundPos-1;
1590 output_format[le]='\0';
1591 sprintf(extra,"%s",&extra[foundPos]);
1592 trim(extra);
1593
1594 /* right */
1595 // \0
1596 sprintf(output_format,"%s\" width=\"%s",output_format,extra);
1597 foundPos=0;
1598 find_str(' ',extra,&foundPos);
1599 le = (strlen(output_format) - strlen(extra))+foundPos-1;
1600 output_format[le]='\0';
1601 sprintf(extra,"%s",&extra[foundPos]);
1602 trim(extra);
1603
1604 /* bottom */
1605 // \0
1606 sprintf(output_format,"%s\" height=\"%s",output_format,extra);
1607 foundPos=0;
1608 find_str(' ',extra,&foundPos);
1609 if (foundPos!=0)
1610 {
1611 le = (strlen(output_format) - strlen(extra))+foundPos-1;
1612 size = strlen(&output_format[le]);
1613 output_format[le]='\0';
1614 sprintf(extra,"%s",&output_format[le+1]);
1615 trim(extra);
1616
1617 /* style */
1618 size = strlen(output_format) + strlen(extra) + 9;
1619 sprintf(output_format,"%s\" style=\"%s",output_format,extra);
1620 output_format[size]='\0';
1621 foundPos=0;
1622 find_str(' ',extra,&foundPos);
1623
1624 if (*output_resid!='\0')
1625 {
1626 sprintf(output_format,"%s\"><![CDATA[%s]]></obj>\n",output_format,output_resid);
1627 }
1628 else
1629 {
1630 sprintf(output_format,"%s\"></obj>\n",output_format);
1631 }
1632 }
1633 else
1634 {
1635 if (*output_resid!='\0')
1636 sprintf(output_format,"%s\" style=\"\"><![CDATA[%s]]></obj>\n",output_format,output_resid);
1637 else
1638 sprintf(output_format,"%s\" style=\"\"></obj>\n",output_format);
1639 }
1640
1641 *output_resid='\0';
1642 }
1643
1644
1645 void DialogCMDBuild2(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text)
1646 {
1647 long le;
1648
1649 stringbugs(output_resid,true);
1650 sprintf(output_resid,"%s",&output_resid[pos]);
1651 trim(output_resid);
1652
1653 le = strlen(output_resid);
1654 if (*output_resid=='"')
1655 *output_resid=' ';
1656 if (output_resid[le-1]=='"')
1657 output_resid[le-1]=' ';
1658
1659 trim(output_resid);
1660 sprintf(output_format,"%s <obj type=\"%s\"><![CDATA[%s]]></obj>\n",output_format,text,output_resid);
1661 *output_resid='\0';
1662 }
1663
1664 // input : CONTROL "",101,"Static",SS_SIMPLE | SS_NOPREFIX,3,6,150,10
1665 void DialogCMDBuild3(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text)
1666 {
1667 long foundPos=0;
1668 long foundNextPos=0;
1669 long le;
1670 long count=0;
1671 long save1;
1672 long save2;
1673
1674 sprintf(output_resid,"%s",&output_resid[pos]);
1675 trim(output_resid);
1676
1677 find_str('"',output_resid,&foundPos);
1678 find_str('"',&output_resid[foundPos],&foundNextPos);
1679
1680 save1=foundPos;
1681 save2=foundNextPos;
1682
1683 sprintf(output_format,"%s <obj type=\"%s\" rc_name=\"",output_format,text);
1684
1685 le=strlen(output_format);
1686 count=foundNextPos+foundPos;
1687 if (output_resid[count]==',')
1688 output_resid[count]=' ';
1689 foundPos=0;
1690 find_str(',',&output_resid[count],&foundPos);
1691 sprintf(output_format,"%s%s\"",output_format,&output_resid[count]);
1692 output_format[le+foundPos]='\0';
1693 stringbugs(&output_format[le],false);
1694 count+=foundPos;
1695
1696 /* prop */
1697 sprintf(output_format,"%s\" prop=\"",output_format);
1698 le=strlen(output_format);
1699 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1700
1701 if (output_resid[count]==',')
1702 output_resid[count]=' ';
1703 foundPos=0;
1704 find_str(',',&output_resid[count],&foundPos);
1705 output_format[le+foundPos]='\0';
1706 stringbugs(&output_format[le],false);
1707 count+=foundPos;
1708
1709 /* style */
1710 sprintf(output_format,"%s\" style=\"",output_format);
1711 le=strlen(output_format);
1712 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1713
1714 if (output_resid[count]==',')
1715 output_resid[count]=' ';
1716 foundPos=0;
1717 find_str(',',&output_resid[count],&foundPos);
1718 output_format[le+foundPos]='\0';
1719 stringbugs(&output_format[le],false);
1720 count+=foundPos;
1721
1722 /* top */
1723 sprintf(output_format,"%s\" left=\"",output_format);
1724 le=strlen(output_format);
1725 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1726
1727 if (output_resid[count]==',')
1728 output_resid[count]=' ';
1729 foundPos=0;
1730 find_str(',',&output_resid[count],&foundPos);
1731 output_format[le+foundPos]='\0';
1732 stringbugs(&output_format[le],false);
1733 count+=foundPos;
1734
1735 /* left */
1736 sprintf(output_format,"%s\" top=\"",output_format);
1737 le=strlen(output_format);
1738 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1739
1740 if (output_resid[count]==',')
1741 output_resid[count]=' ';
1742 foundPos=0;
1743 find_str(',',&output_resid[count],&foundPos);
1744 output_format[le+foundPos]='\0';
1745 stringbugs(&output_format[le],false);
1746 count+=foundPos;
1747
1748 /* right */
1749 sprintf(output_format,"%s\" width=\"",output_format);
1750 le=strlen(output_format);
1751 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1752
1753 if (output_resid[count]==',')
1754 output_resid[count]=' ';
1755 foundPos=0;
1756 find_str(',',&output_resid[count],&foundPos);
1757 output_format[le+foundPos]='\0';
1758 stringbugs(&output_format[le],false);
1759 count+=foundPos;
1760
1761 /* bottom */
1762 sprintf(output_format,"%s\" height=\"",output_format);
1763 le=strlen(output_format);
1764 sprintf(output_format,"%s%s",output_format,&output_resid[count]);
1765 stringbugs(&output_format[le],false);
1766
1767 /* string */
1768 output_resid[save1+save2]='\0';
1769 stringbugs(output_resid,true);
1770
1771
1772 if (*output_resid!='\0')
1773 sprintf(output_format,"%s\"><![CDATA[%s]]></obj>\n",output_format,output_resid);
1774 else
1775 sprintf(output_format,"%s\"></obj>\n",output_format);
1776
1777 *output_resid='\0';
1778 }
1779