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
7 * CopyRight 20/9-2006 by Magnus Olsen (magnus@greatlord.com)
8 * Licen GPL version 2.0
21 int ansiCodePage(int codepage
, unsigned char *inBuffer
, unsigned char *outBuffer
, int Lenght
);
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
);
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
);
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
);
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
);
46 return -1 : No file found
47 return -2 : Fail open file
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
57 int main(int argc
, char * argv
[])
61 unsigned char * buffer
;
62 unsigned char * output_text
;
63 unsigned char * output_resid
;
64 unsigned char * output_format
;
67 long buf_size_calc
= 0;
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");
81 if ((fp
= fopen(argv
[1],"rb"))==NULL
)
83 printf("Fail open file %s by %s\n",argv
[1],argv
[0]);
93 printf("Fail seek\n");
100 printf("Fail get size\n");
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
112 buf_size_calc
= (buf_size
*4) + 2048;
114 fseek(fp
,0,SEEK_SET
);
118 printf("Fail seek\n");
125 printf("Fail size of the file is 0 bytes\n");
129 buffer
=(char *)malloc(buf_size_calc
);
133 printf("Fail malloc memory\n");
137 output_text
=(char *)malloc(buf_size_calc
);
138 if (output_text
== NULL
)
142 printf("Fail malloc memory\n");
146 output_resid
=(char *)malloc(buf_size_calc
);
147 if (output_resid
== NULL
)
152 printf("Fail malloc memory\n");
156 output_format
=(char *)malloc(buf_size_calc
);
157 if (output_format
== NULL
)
163 printf("Fail malloc memory\n");
167 //fread(buffer,1,buf_size,fp);
168 fread(buffer
,buf_size
,1,fp
);
172 printf("Fail to read the file\n");
177 /* Now we can write our parser */
179 paraser1(buffer
, buf_size
, output_text
, output_resid
, output_format
,"UTF-8");
180 // printf ("%s",output_format);
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
));
186 if ((Outfp
= fopen(argv
[3],"wb")) != NULL
)
188 fwrite(output_resid
,1,buf_size_calc
,Outfp
);
197 if(output_text
!=NULL
)
199 if(output_resid
!=NULL
)
201 if(output_format
!=NULL
)
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
)
216 memset(output_text
,0,buf_size
);
217 memset(output_resid
,0,buf_size
);
218 memset(output_format
,0,buf_size
);
220 sprintf(output_format
,"<?xml version=\"1.0\" encoding=\"%s\"?>\n<resource>\n",iso_type
);
223 while(pos
< buf_size
)
229 /* create a row string so we can easy scan it */
230 find_str('\n',&buf
[pos
],&foundPos
);
234 row_size
= foundPos
- 1;
236 /* found a new row */
237 strncpy(row
, &buf
[pos
], row_size
);
245 row_size
= buf_size
- pos
;
247 /* no new row found in the buffer */
248 strncpy(row
, &buf
[pos
], buf_size
- pos
);
255 /* Detect Basic command and send it to own paraser */
259 if (strncmp("/*",row
,2)==0)
261 ParserComment(&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
265 if (strncmp("//",row
,2)==0)
267 ParserComment(&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
270 if (strncmp("#",row
,1)==0)
272 ParserComment(&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
276 stringbugs(row
,true);
280 find_str2 ("LANGUAGE ",row
,&foundPos
,output_resid
,output_text
);
283 ParserLang("LANGUAGE", output_resid
, output_text
, output_format
);
290 find_str2 ("STRINGTABLE ",row
,&foundPos
,output_resid
,output_text
);
293 ParserCMD3("STRINGTABLE", output_resid
, output_text
, output_format
);
294 ParserString(&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
301 find_str2 (" DIALOGEX ",row
,&foundPos
,output_resid
,output_text
);
304 ParserCMD2("DIALOGEX", output_resid
, output_text
, output_format
);
305 ParserDialog("DIALOGEX",&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
312 find_str2 (" DIALOG ",row
,&foundPos
,output_resid
,output_text
);
315 ParserCMD2("DIALOG", output_resid
, output_text
, output_format
);
316 ParserDialog("DIALOG",&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
323 find_str2 (" ACCELERATORS\0",row
,&foundPos
,output_resid
,output_text
);
326 ParserCMD1("ACCELERATORS", output_resid
, output_text
, output_format
);
327 ParserAccelerators(&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
334 find_str2 (" MENU\0",row
,&foundPos
,output_resid
,output_text
);
337 ParserCMD1("MENU", output_resid
, output_text
, output_format
);
338 ParserMenu("MENU",&pos
, buf
, buf_size
, output_text
, output_resid
, output_format
);
345 sprintf(output_format
,"%s</resource>\n",output_format
);
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
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>
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
373 void ParserCMD1(unsigned char *text
, unsigned char *output_resid
, unsigned char *output_text
, unsigned char *output_format
)
377 stringbugs(output_resid
,false);
378 stringbugs(output_text
,false);
382 if (strlen(output_text
) == le
)
384 sprintf(output_format
,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\"></obj>\n",output_format
,text
,text
,output_resid
);
386 else if (output_text
[le
]==' ')
388 sprintf(output_format
,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\">DISCARDABLE</obj>\n",output_format
,text
,text
,output_resid
);
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
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>
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
415 void ParserCMD2(unsigned char *text
, unsigned char *output_resid
, unsigned char *output_text
, unsigned char *output_format
)
420 stringbugs(output_resid
,false);
421 stringbugs(output_text
,false);
425 sprintf(output_format
,"%s<group name=\"%s\">\n <obj type=\"%s\" rc_name=\"%s\" ",output_format
,text
,text
,output_resid
);
427 find_str2 (" DISCARDABLE ",output_text
,&flag
,output_resid
,output_text
);
432 *output_resid
='\0'; /* not in use futer */
433 flag
=0; /* DISCARDABLE off */
434 sprintf(output_text
,"%s",&output_text
[le
]);
439 *output_resid
='\0'; /* not in use futer */
440 flag
=1; /* DISCARDABLE on */
441 sprintf(output_text
,"%s",&output_text
[11]);
445 /* data is looking like this 0 1 2 3 now */
449 find_str2 (" ",output_text
,&flag
,output_resid
,output_text
);
453 sprintf(output_format
,"%sleft=\"%s\" ",output_format
,output_resid
);
457 find_str2 (" ",output_text
,&flag
,output_resid
,output_text
);
461 sprintf(output_format
,"%stop=\"%s\" ",output_format
,output_resid
);
465 find_str2 (" ",output_text
,&flag
,output_resid
,output_text
);
470 sprintf(output_format
,"%swidth=\"%s\" height=\"%s\"></obj>\n",output_format
,output_resid
,output_text
);
472 sprintf(output_format
,"%swidth=\"%s\" height=\"%s\">DISCARDABLE</obj>\n",output_format
,output_resid
,output_text
);
478 input : STRINGTABLE DISCARDABLE LANG LANG_TAG LANG_TAG
479 input : STRINGTABLE DISCARDABLE LANG
480 input : STRINGTABLE LANG LANG_TAG LANG_TAG
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>
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
496 void ParserCMD3(unsigned char *text
, unsigned char *output_resid
, unsigned char *output_text
, unsigned char *output_format
)
500 stringbugs(output_resid
,false);
501 stringbugs(output_text
,false);
503 find_str2 (" ",output_text
,&foundPos
,output_resid
,output_text
);
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
);
510 sprintf(output_format
,"%s<group name=\"%s\">\n <obj type=\"%s\"></obj>\n",output_format
,output_resid
,output_text
);
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>
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
527 void ParserLang(unsigned char *text
, unsigned char *output_resid
, unsigned char *output_text
, unsigned char *output_format
)
531 stringbugs(output_resid
,false);
532 stringbugs(output_text
,false);
534 sprintf(output_text
,"%s",&output_text
[strlen(text
)+1]);
536 /* split the lang into two string */
537 find_str2 (" ",output_text
,&foundPos
,output_resid
,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
);
547 input : / * sadasdas asdasd asdas ... * /
548 output :<obj type=\"COMMENT\"><![CDATA[ sadasdas asdasd asdas ... ]]></obj>
550 input : / * sadasdas asdasd asdas ... * /
551 output :<obj type=\"COMMENT\"><![CDATA[ sadasdas asdasd asdas ... ]]></obj>
554 output :<obj type=\"COMMENT\"><![CDATA[#if x]]></obj>
557 output :<obj type=\"COMMENT\"><![CDATA[// hi]]></obj>
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
567 void ParserComment(long *pos
, unsigned char *buf
, long buf_size
, unsigned char * output_text
, unsigned char * output_resid
, unsigned char * output_format
)
572 unsigned char *row
= output_text
;
575 row_size
= strlen(row
);
576 if (strncmp("//",&row
[0],2)==0)
578 sprintf(output_format
,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s]]></obj>\n</group>\n",output_format
,row
);
581 if (strncmp("#",&row
[0],1)==0)
583 sprintf(output_format
,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s]]></obj>\n</group>\n",output_format
,row
);
587 for (foundNextPos
=0;foundNextPos
<row_size
;foundNextPos
++)
589 if (strncmp("*/",&row
[foundNextPos
],2)==0)
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
);
601 sprintf(output_format
,"%s<group name=\"COMMENT\">\n <obj type=\"COMMENT\"><![CDATA[%s\n",output_format
,output_text
);
603 while(*pos
< buf_size
)
608 /* create a row string so we can easy scan it */
609 find_str('\n',&buf
[*pos
],&foundPos
);
612 row_size
= foundPos
- 1;
614 /* found a new row */
615 strncpy(row
, &buf
[*pos
], foundPos
);
625 row_size
= buf_size
- *pos
;
627 /* no new row found in the buffer */
628 strncpy(row
, &buf
[*pos
], buf_size
- *pos
);
632 /* Search now after end of comment */
633 row_size
=strlen(row
);
634 for (foundNextPos
=0;foundNextPos
<row_size
;foundNextPos
++)
636 if (strncmp("*/",&row
[foundNextPos
],2)==0)
638 row_size
=row_size
- (foundNextPos
+2);
640 row
[foundNextPos
+2]='\0';
641 sprintf(output_format
,"%s%s]]></obj>\n</group>\n",output_format
,row
);
645 sprintf(output_format
,"%s%s\n",output_format
,row
);
654 input : "^A", CMD_SELECT_ALL
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" />
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
668 void ParserAccelerators(long *pos
, unsigned char *buf
, long buf_size
, unsigned char * output_text
, unsigned char * output_resid
, unsigned char * output_format
)
673 char *row
= output_text
;
677 while(*pos
< buf_size
)
682 /* create a row string so we can easy scan it */
683 find_str('\n',&buf
[*pos
],&foundPos
);
686 row_size
= foundPos
- 1;
688 /* found a new row */
689 strncpy(row
, &buf
[*pos
], foundPos
);
699 row_size
= buf_size
- *pos
;
701 /* no new row found in the buffer */
702 strncpy(row
, &buf
[*pos
], buf_size
- *pos
);
706 stringbugs(row
,true);
709 if ((strcmp(row
,"BEGIN")==0) || (strcmp(row
,"{")==0))
712 sprintf(output_format
,"%s <obj type=\"ACCELERATORS\" command=\"BEGIN\" />\n",output_format
);
718 if ((strcmp(row
,"END")==0) || (strcmp(row
,"}")==0))
720 sprintf(output_format
,"%s <obj type=\"ACCELERATORS\" command=\"END\" />\n</group>\n",output_format
);
722 *output_resid
= '\0';
728 find_str('"',row
,&foundPos
);
729 find_str('"',&row
[foundPos
],&foundNextPos
);
731 if ((foundPos
!=0) && (foundNextPos
!=0))
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';
741 find_str('"',row
,&foundPos
);
748 sprintf(output_format
,"%s\"><![CDATA[%s]]></obj>\n",output_format
,row
);
757 input : IDS_HINT_BLANK "text"
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" />
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
771 void ParserString(long *pos
, unsigned char *buf
, long buf_size
, unsigned char * output_text
, unsigned char * output_resid
, unsigned char * output_format
)
775 unsigned char *row
= output_text
;
778 while(*pos
< buf_size
)
783 /* create a row string so we can easy scan it */
784 find_str('\n',&buf
[*pos
],&foundPos
);
788 row_size
= foundPos
- 1;
790 /* found a new row */
791 strncpy(row
, &buf
[*pos
], foundPos
);
801 row_size
= buf_size
- *pos
;
803 /* no new row found in the buffer */
804 strncpy(row
, &buf
[*pos
], buf_size
- *pos
);
808 stringbugs(row
,true);
813 if ((strcmp(row
,"BEGIN")==0) || (strcmp(row
,"{")==0))
817 sprintf(output_format
,"%s <obj type=\"STRINGTABLE\" command=\"BEGIN\" />\n",output_format
);
822 if ((strcmp(row
,"END")==0) || (strcmp(row
,"}")==0))
824 sprintf(output_format
,"%s <obj type=\"STRINGTABLE\" command=\"END\" />\n</group>\n",output_format
);
826 *output_resid
= '\0';
832 /* the split code here */
834 find_str2 (" ",row
,&foundPos
,output_resid
,output_text
);
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
);
844 sprintf(output_format
,"%s <obj type=\"STRING\" rc_name=\"%s\"></obj>\n",output_format
,output_resid
);
855 output : <obj type="DIALOG" command="BEGIN" />
856 output : <obj type="DIALOGEX" command="BEGIN" />
859 output : <obj type="END" command="BEGIN" />
860 output : <obj type="END" command="BEGIN" />
863 output : <obj type="DIALOG" command="BEGIN" />
864 output : <obj type="DIALOGEX" command="BEGIN" />
867 output : <obj type="END" command="BEGIN" />
868 output : <obj type="END" command="BEGIN" />
870 input : FONT 8, "MS Shell Dlg"
871 output : <obj type="FONT" size="8" name="MS Shell Dlg"></obj>
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>
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>
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
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
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>
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>
898 input : CAPTION "Execute"
899 input : EXSTYLE WS_EX_APPWINDOW
900 input : STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
902 output : <obj type="STYLE">DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU</obj>
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
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
)
916 unsigned char *row
= output_text
;
923 while(*pos
< buf_size
)
928 /* create a row string so we can easy scan it */
929 find_str('\n',&buf
[*pos
],&foundPos
);
932 row_size
= foundPos
- 1;
934 /* found a new row */
935 strncpy(row
, &buf
[*pos
], foundPos
);
945 row_size
= buf_size
- *pos
;
947 /* no new row found in the buffer */
948 strncpy(row
, &buf
[*pos
], buf_size
- *pos
);
952 //stringbugs(row,true);
955 if ((strcmp(row
,"BEGIN")==0) || (strcmp(row
,"{")==0))
957 if ((strcmp(row
,"END")==0) || (strcmp(row
,"}")==0))
960 if (strncmp("STYLE ",row
,6)==0)
962 if (strncmp("CAPTION ",row
,8)==0)
964 if (strncmp("FONT ",row
,5)==0)
966 if (strncmp("CONTROL ",row
,8)==0)
968 if (strncmp("EDITTEXT ",row
,9)==0)
970 if (strncmp("DEFPUSHBUTTON ",row
,14)==0)
972 if (strncmp("PUSHBUTTON ",row
,11)==0)
974 if (strncmp("LTEXT ",row
,6)==0)
976 if (strncmp("GROUPBOX ",row
,9)==0)
978 if (strncmp("ICON ",row
,5)==0)
980 if (strncmp("EXSTYLE ",row
,8)==0)
982 if (strncmp(row
,"LISTBOX ",8)==0)
984 if (strncmp(row
,"COMBOBOX ",9)==0)
987 if ((*output_resid
!=0) && (commandfound
!=0))
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");
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");
1018 if (strncmp(output_resid
,"FONT ",5)==0)
1020 stringbugs(output_resid
,true);
1022 sprintf(output_resid
,"%s",&output_resid
[5]);
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
);
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]);
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')
1042 sprintf(output_format
,"%s></obj>\n",output_format
);
1046 sprintf(output_format
,"%s\">%s</obj>\n",output_format
,&output_resid
[foundPos
]);
1055 if (commandfound
==1)
1057 sprintf(output_format
,"%s <obj type=\"%s\" command=\"BEGIN\" />\n",output_format
,text
);
1059 if (commandfound
==2)
1061 sprintf(output_format
,"%s <obj type=\"%s\" command=\"END\" />\n</group>\n",output_format
,text
);
1065 sprintf(output_resid
,"%s%s",output_resid
,row
);
1070 //////////////////////////
1076 output : <obj type="DIALOG" command="BEGIN" />
1077 output : <obj type="DIALOGEX" command="BEGIN" />
1080 output : <obj type="END" command="BEGIN" />
1081 output : <obj type="END" command="BEGIN" />
1084 output : <obj type="DIALOG" command="BEGIN" />
1085 output : <obj type="DIALOGEX" command="BEGIN" />
1088 output : <obj type="END" command="BEGIN" />
1089 output : <obj type="END" command="BEGIN" />
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
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
)
1101 long foundNextPos
=0;
1103 unsigned char *row
= output_text
;
1104 long commandfound
=0;
1111 while(*pos
< buf_size
)
1116 /* create a row string so we can easy scan it */
1117 find_str('\n',&buf
[*pos
],&foundPos
);
1120 row_size
= foundPos
- 1;
1122 /* found a new row */
1123 strncpy(row
, &buf
[*pos
], foundPos
);
1133 row_size
= buf_size
- *pos
;
1135 /* no new row found in the buffer */
1136 strncpy(row
, &buf
[*pos
], buf_size
- *pos
);
1140 //stringbugs(row,true);
1141 stringbugs2(row
,true);
1143 if ((strcmp(row
,"BEGIN")==0) || (strcmp(row
,"{")==0))
1145 if ((strcmp(row
,"END")==0) || (strcmp(row
,"}")==0))
1148 if (strncmp("POPUP ",row
,6)==0)
1150 if (strncmp("MENUITEM ",row
,8)==0)
1154 if ((*output_resid
!=0) && (commandfound
!=0))
1156 if (strncmp(output_resid
,"POPUP ",6)==0)
1158 sprintf(output_resid
,"%s",&output_resid
[5]);
1160 sprintf(output_format
,"%s<obj type=\"POPUP\"><![CDATA[%s]]></obj>\n",output_format
,output_resid
);
1164 if (strncmp(output_resid
,"MENUITEM ",9)==0)
1166 sprintf(output_resid
,"%s",&output_resid
[8]);
1168 if (strcmp(output_resid
,"SEPARATOR")==0)
1170 sprintf(output_format
,"%s<obj type=\"MENUITEMSEPERATOR\"></obj>\n",output_format
);
1177 find_str('"',output_resid
,&foundPos
);
1178 find_str('"',&output_resid
[foundPos
],&foundNextPos
);
1180 stringbugs(&output_resid
[foundPos
+foundNextPos
],true);
1182 if ((foundPos
+foundNextPos
)==0)
1184 sprintf(output_format
,"%s<obj type=\"MENUITEM\" rc_name=\"%s\"></obj>\n",output_format
,&output_resid
[foundPos
+foundNextPos
]);
1188 sprintf(output_format
,"%s<obj type=\"MENUITEM\" rc_name=\"%s\">",output_format
,&output_resid
[foundPos
+foundNextPos
]);
1190 output_resid
[foundPos
+foundNextPos
]='\0';
1193 sprintf(output_format
,"%s<![CDATA[%s]]></obj>\n",output_format
,output_resid
);
1207 if (commandfound
==1)
1211 sprintf(output_format
,"%s<obj type=\"%s\" command=\"BEGIN\" />\n",output_format
,text
);
1213 sprintf(output_format
,"%s<obj type=\"POPUP\" command=\"BEGIN\" />\n",output_format
);
1217 if (commandfound
==2)
1223 sprintf(output_format
,"%s<obj type=\"%s\" command=\"END\" />\n",output_format
,text
);
1225 sprintf(output_format
,"%s<obj type=\"POPUP\" command=\"END\" />\n",output_format
);
1229 sprintf(output_format
,"%s</group>\n",output_format
);
1234 sprintf(output_resid
,"%s%s",output_resid
,row
);
1240 void stringbugs(unsigned char *buf
, int shift2
)
1243 long foundNextPos
=0;
1249 for (t
=0;t
<strlen(buf
);t
++)
1253 if (strncmp(",",&buf
[t
],1)==0)
1258 if (strncmp("\"",&buf
[t
],1)==0)
1263 if (strncmp("/*",&buf
[t
],2)==0)
1272 if (strncmp("*/",&buf
[t
],2)==0)
1288 for (t
=0;t
<strlen(buf
);t
++)
1290 if ((foundPos
==0) && (foundNextPos
==0))
1292 if (strncmp(",",&buf
[t
],1)==0)
1297 if (strncmp("\"",&buf
[t
],1)==0)
1302 if (strncmp("/*",&buf
[t
],2)==0)
1313 if (strncmp("*/",&buf
[t
],2)==0)
1324 if (foundNextPos
!=0)
1326 if (strncmp("\"",&buf
[t
],1)==0)
1336 /* have remove all wrong syntax */
1339 void stringbugs2(unsigned char *buf
, int shift2
)
1342 long foundNextPos
=0;
1348 for (t
=0;t
<strlen(buf
);t
++)
1353 if (strncmp("\"",&buf
[t
],1)==0)
1358 if (strncmp("/*",&buf
[t
],2)==0)
1367 if (strncmp("*/",&buf
[t
],2)==0)
1383 for (t
=0;t
<strlen(buf
);t
++)
1385 if ((foundPos
==0) && (foundNextPos
==0))
1388 if (strncmp("\"",&buf
[t
],1)==0)
1393 if (strncmp("/*",&buf
[t
],2)==0)
1404 if (strncmp("*/",&buf
[t
],2)==0)
1415 if (foundNextPos
!=0)
1417 if (strncmp("\"",&buf
[t
],1)==0)
1427 /* have remove all wrong syntax */
1432 void trim(unsigned char* buf
)
1447 if (isspace(buf
[le
-1])!=0)
1461 if (isspace(buf
[0])!=0)
1463 strncpy(&buf
[0],&buf
[1],le
-1);
1473 void find_str(unsigned char asc
,unsigned char *buf
, long *foundPos
)
1484 *foundPos
= *foundPos
+t
+1;
1489 /* for end of line the \ is a special case */
1490 if ((asc
== '\n') && (foundPos
!=0) && (buf
[t
-2]=='\\'))
1494 find_str(asc
, &buf
[extra
], foundPos
);
1499 void find_str2(unsigned char *asc
, unsigned char *buf
, long *foundPos
,
1500 unsigned char * output_resid
, unsigned char *output_text
)
1509 if ((lec
==0) || (le
==0))
1516 if (strncmp(&buf
[t
],asc
,lec
)==0)
1518 long softfoundPos
=0;
1520 *foundPos
= *foundPos
+t
+lec
;
1521 softfoundPos
= *foundPos
;
1523 strncpy(output_resid
, &buf
[0], t
);
1526 strncpy(output_text
, &buf
[t
], le
-t
);
1527 output_text
[ le
-t
]=0;
1535 void DialogCMDBuild1(unsigned char *output_resid
, unsigned char *output_format
, long pos
, unsigned char * text
)
1539 unsigned char extra
[1000];
1541 long foundNextPos
=0;
1545 stringbugs(output_resid
,true);
1546 sprintf(output_resid
,"%s",&output_resid
[pos
]);
1549 find_str('"',output_resid
,&foundPos
);
1550 find_str('"',&output_resid
[foundPos
],&foundNextPos
);
1552 if ((foundPos
!=0) && (foundPos
!=0))
1554 strcpy(extra
,&output_resid
[foundPos
+foundNextPos
]);
1557 output_resid
[foundPos
+foundNextPos
]='\0';
1562 strcpy(extra
,output_resid
);
1566 sprintf(output_format
,"%s <obj type=\"%s\" rc_name=\"%s",output_format
,text
,extra
);
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
]);
1576 sprintf(output_format
,"%s\" left=\"%s",output_format
,extra
);
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
]);
1586 sprintf(output_format
,"%s\" top=\"%s",output_format
,extra
);
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
]);
1596 sprintf(output_format
,"%s\" width=\"%s",output_format
,extra
);
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
]);
1606 sprintf(output_format
,"%s\" height=\"%s",output_format
,extra
);
1608 find_str(' ',extra
,&foundPos
);
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]);
1618 size
= strlen(output_format
) + strlen(extra
) + 9;
1619 sprintf(output_format
,"%s\" style=\"%s",output_format
,extra
);
1620 output_format
[size
]='\0';
1622 find_str(' ',extra
,&foundPos
);
1624 if (*output_resid
!='\0')
1626 sprintf(output_format
,"%s\"><![CDATA[%s]]></obj>\n",output_format
,output_resid
);
1630 sprintf(output_format
,"%s\"></obj>\n",output_format
);
1635 if (*output_resid
!='\0')
1636 sprintf(output_format
,"%s\" style=\"\"><![CDATA[%s]]></obj>\n",output_format
,output_resid
);
1638 sprintf(output_format
,"%s\" style=\"\"></obj>\n",output_format
);
1645 void DialogCMDBuild2(unsigned char *output_resid
, unsigned char *output_format
, long pos
, unsigned char * text
)
1649 stringbugs(output_resid
,true);
1650 sprintf(output_resid
,"%s",&output_resid
[pos
]);
1653 le
= strlen(output_resid
);
1654 if (*output_resid
=='"')
1656 if (output_resid
[le
-1]=='"')
1657 output_resid
[le
-1]=' ';
1660 sprintf(output_format
,"%s <obj type=\"%s\"><![CDATA[%s]]></obj>\n",output_format
,text
,output_resid
);
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
)
1668 long foundNextPos
=0;
1674 sprintf(output_resid
,"%s",&output_resid
[pos
]);
1677 find_str('"',output_resid
,&foundPos
);
1678 find_str('"',&output_resid
[foundPos
],&foundNextPos
);
1683 sprintf(output_format
,"%s <obj type=\"%s\" rc_name=\"",output_format
,text
);
1685 le
=strlen(output_format
);
1686 count
=foundNextPos
+foundPos
;
1687 if (output_resid
[count
]==',')
1688 output_resid
[count
]=' ';
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);
1697 sprintf(output_format
,"%s\" prop=\"",output_format
);
1698 le
=strlen(output_format
);
1699 sprintf(output_format
,"%s%s",output_format
,&output_resid
[count
]);
1701 if (output_resid
[count
]==',')
1702 output_resid
[count
]=' ';
1704 find_str(',',&output_resid
[count
],&foundPos
);
1705 output_format
[le
+foundPos
]='\0';
1706 stringbugs(&output_format
[le
],false);
1710 sprintf(output_format
,"%s\" style=\"",output_format
);
1711 le
=strlen(output_format
);
1712 sprintf(output_format
,"%s%s",output_format
,&output_resid
[count
]);
1714 if (output_resid
[count
]==',')
1715 output_resid
[count
]=' ';
1717 find_str(',',&output_resid
[count
],&foundPos
);
1718 output_format
[le
+foundPos
]='\0';
1719 stringbugs(&output_format
[le
],false);
1723 sprintf(output_format
,"%s\" left=\"",output_format
);
1724 le
=strlen(output_format
);
1725 sprintf(output_format
,"%s%s",output_format
,&output_resid
[count
]);
1727 if (output_resid
[count
]==',')
1728 output_resid
[count
]=' ';
1730 find_str(',',&output_resid
[count
],&foundPos
);
1731 output_format
[le
+foundPos
]='\0';
1732 stringbugs(&output_format
[le
],false);
1736 sprintf(output_format
,"%s\" top=\"",output_format
);
1737 le
=strlen(output_format
);
1738 sprintf(output_format
,"%s%s",output_format
,&output_resid
[count
]);
1740 if (output_resid
[count
]==',')
1741 output_resid
[count
]=' ';
1743 find_str(',',&output_resid
[count
],&foundPos
);
1744 output_format
[le
+foundPos
]='\0';
1745 stringbugs(&output_format
[le
],false);
1749 sprintf(output_format
,"%s\" width=\"",output_format
);
1750 le
=strlen(output_format
);
1751 sprintf(output_format
,"%s%s",output_format
,&output_resid
[count
]);
1753 if (output_resid
[count
]==',')
1754 output_resid
[count
]=' ';
1756 find_str(',',&output_resid
[count
],&foundPos
);
1757 output_format
[le
+foundPos
]='\0';
1758 stringbugs(&output_format
[le
],false);
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);
1768 output_resid
[save1
+save2
]='\0';
1769 stringbugs(output_resid
,true);
1772 if (*output_resid
!='\0')
1773 sprintf(output_format
,"%s\"><![CDATA[%s]]></obj>\n",output_format
,output_resid
);
1775 sprintf(output_format
,"%s\"></obj>\n",output_format
);