/* * This is a standalone rc langues to xml parser * do not use windows or linux specfiy syntax or functions * use only pure ansi C, this program is also runing on * linux apachie webserver and being use in ReactOS website * * CopyRight 20/9-2006 by Magnus Olsen (magnus@greatlord.com) * Licen GPL version 2.0 */ #include #include #include #include #define true 1 #define false 0 int ansiCodePage(int codepage, unsigned char *inBuffer, unsigned char *outBuffer, int Lenght); int paraser1(unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format, unsigned char *iso_type); void find_str(unsigned char asc, unsigned char *buf, long *foundPos); void find_str2(unsigned char *asc, unsigned char *buf, long *foundPos, unsigned char * output_resid, unsigned char *output_text ); void trim(unsigned char* buf); void stringbugs(unsigned char *buf, int shift2); void stringbugs2(unsigned char *buf, int shift2); void ParserCMD1(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format); void ParserCMD2(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format); void ParserCMD3(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format); void ParserComment(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format); void ParserLang(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format); void ParserString(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format); 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); void DialogCMDBuild1(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text); void DialogCMDBuild2(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text); void DialogCMDBuild3(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text); void ParserAccelerators(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format); 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); /* return -1 : No file found return -2 : Fail open file return -3 : Fail seek return -4 : Fail get size return -5 : Fail size of the file is 0 bytes return -6 : Fail malloc memory return -7 : Fail to read the file return -8 : Fail to write to the file return -9 : Fail to open write file */ int main(int argc, char * argv[]) { FILE * fp; FILE * Outfp; unsigned char * buffer; unsigned char * output_text; unsigned char * output_resid; unsigned char * output_format; long buf_size; long buf_size_calc = 0; if (argc!=4) { printf("Help\n"); printf("%s inputfile iso-type\n\n",argv[0]); printf("example %s sv.rc 28591 sv.xml\n\n",argv[0]); printf("Contry table\n"); printf("se (Swedish = Windows-28591 (Latin1 ISO-8859-1)\n"); return -1; } if ((fp = fopen(argv[1],"rb"))==NULL) { printf("Fail open file %s by %s\n",argv[1],argv[0]); return -2; } fseek(fp,0,SEEK_END); if (ferror(fp) !=0) { fclose(fp); printf("Fail seek\n"); return -3; } buf_size = ftell(fp); if (ferror(fp) !=0) { fclose(fp); printf("Fail get size\n"); return -4; } /* We make sure it is least 4 times + 2K biger for we can grow around 2-3 times biger so it better to make safe assume how much memory we need */ buf_size_calc = (buf_size*4) + 2048; fseek(fp,0,SEEK_SET); if (ferror(fp) !=0) { fclose(fp); printf("Fail seek\n"); return -3; } if (buf_size==0) { fclose(fp); printf("Fail size of the file is 0 bytes\n"); return -5; } buffer =(char *)malloc(buf_size_calc); if (buffer == NULL) { fclose(fp); printf("Fail malloc memory\n"); return -6; } output_text =(char *)malloc(buf_size_calc); if (output_text == NULL) { free(buffer); fclose(fp); printf("Fail malloc memory\n"); return -6; } output_resid =(char *)malloc(buf_size_calc); if (output_resid == NULL) { free(buffer); free(output_text); fclose(fp); printf("Fail malloc memory\n"); return -6; } output_format =(char *)malloc(buf_size_calc); if (output_format == NULL) { free(buffer); free(output_text); free(output_resid); fclose(fp); printf("Fail malloc memory\n"); return -6; } //fread(buffer,1,buf_size,fp); fread(buffer,buf_size,1,fp); if (ferror(fp) !=0) { fclose(fp); printf("Fail to read the file\n"); return -7; } fclose(fp); /* Now we can write our parser */ paraser1(buffer, buf_size, output_text, output_resid, output_format,"UTF-8"); // printf ("%s",output_format); /* Now we convert to utf-8 */ memset(output_resid,0,buf_size_calc); buf_size_calc = ansiCodePage(atoi(argv[2]), output_format, output_resid, strlen(output_format)); if ((Outfp = fopen(argv[3],"wb")) != NULL ) { fwrite(output_resid,1,buf_size_calc,Outfp); fclose(Outfp); } if(buffer!=NULL) free(buffer); if(output_text!=NULL) free(output_text); if(output_resid!=NULL) free(output_resid); if(output_format!=NULL) free(output_format); return 0; } int paraser1(unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format, unsigned char *iso_type) { unsigned char *row; long foundPos=0; long foundNextPos=0; long row_size=0; long pos=0; memset(output_text,0,buf_size); memset(output_resid,0,buf_size); memset(output_format,0,buf_size); sprintf(output_format,"\n\n",iso_type); row = output_text; while(pos < buf_size) { foundPos=0; foundNextPos=0; row_size=0; /* create a row string so we can easy scan it */ find_str('\n',&buf[pos],&foundPos); if (foundPos !=0) { row_size = foundPos - 1; /* found a new row */ strncpy(row, &buf[pos], row_size); pos+=foundPos; if (foundPos >=2) row[row_size -1]=0; } else { row_size = buf_size - pos; /* no new row found in the buffer */ strncpy(row, &buf[pos], buf_size - pos); pos= buf_size; } trim(row); foundPos=0; /* Detect Basic command and send it to own paraser */ if (*row==0) continue; if (strncmp("/*",row,2)==0) { ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format); continue; } if (strncmp("//",row,2)==0) { ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format); continue; } if (strncmp("#",row,1)==0) { ParserComment(&pos, buf, buf_size, output_text, output_resid, output_format); continue; } stringbugs(row,true); if (foundPos == 0) { find_str2 ("LANGUAGE ",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserLang("LANGUAGE", output_resid, output_text, output_format); continue; } } if (foundPos == 0) { find_str2 ("STRINGTABLE ",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserCMD3("STRINGTABLE", output_resid, output_text, output_format); ParserString(&pos, buf, buf_size, output_text, output_resid, output_format); continue; } } if (foundPos == 0) { find_str2 (" DIALOGEX ",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserCMD2("DIALOGEX", output_resid, output_text, output_format); ParserDialog("DIALOGEX",&pos, buf, buf_size, output_text, output_resid, output_format); continue; } } if (foundPos == 0) { find_str2 (" DIALOG ",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserCMD2("DIALOG", output_resid, output_text, output_format); ParserDialog("DIALOG",&pos, buf, buf_size, output_text, output_resid, output_format); continue; } } if (foundPos == 0) { find_str2 (" ACCELERATORS\0",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserCMD1("ACCELERATORS", output_resid, output_text, output_format); ParserAccelerators(&pos, buf, buf_size, output_text, output_resid, output_format); continue; } } if (foundPos == 0) { find_str2 (" MENU\0",row,&foundPos,output_resid,output_text); if (foundPos != 0) { ParserCMD1("MENU", output_resid, output_text, output_format); ParserMenu("MENU",&pos, buf, buf_size, output_text, output_resid, output_format); continue; } } } // end while sprintf(output_format,"%s\n",output_format); return false; } /* ParserCMD data input : IDM_MDIFRAME MENU DISCARDABLE LANG LANG_TAG LANG_TAG input : IDM_MDIFRAME MENU DISCARDABLE input : IDM_MDIFRAME MENU input : IDM_MDIFRAME ACCELERATORS DISCARDABLE LANG LANG_TAG LANG_TAG input : IDM_MDIFRAME ACCELERATORS DISCARDABLE input : IDM_MDIFRAME ACCELERATORS output : DISCARDABLE output : DISCARDABLE output : output : DISCARDABLE output : DISCARDABLE output : param : output_resid = rc_name ID param : output_text = MENU DISCARDABLE LANG LANG_TAG LANG_TAG param : text = type example MENU param : output_format = xml data store buffer */ void ParserCMD1(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format) { long le; stringbugs(output_resid,false); stringbugs(output_text,false); le = strlen(text); if (strlen(output_text) == le) { sprintf(output_format,"%s\n \n",output_format,text,text,output_resid); } else if (output_text[le]==' ') { sprintf(output_format,"%s\n DISCARDABLE\n",output_format,text,text,output_resid); } } /* ParserCMD2 data input : IDM_MDIFRAME DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG input : IDM_MDIFRAME DIALOG DISCARDABLE 15, 13, 210, 63 input : IDM_MDIFRAME DIALOGEX DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG input : IDM_MDIFRAME DIALOGEX DISCARDABLE 15, 13, 210, 63 output : DISCARDABLE output : output : DISCARDABLE output : param : output_resid = rc_name ID param : output_text = DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG param : text = type example DIALOG param : output_format = xml data store buffer */ void ParserCMD2(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format) { long le; long flag = 0; stringbugs(output_resid,false); stringbugs(output_text,false); le=strlen(text); sprintf(output_format,"%s\n \n",output_format,output_resid,output_text); else sprintf(output_format,"%swidth=\"%s\" height=\"%s\">DISCARDABLE\n",output_format,output_resid,output_text); } /* ParserCMD3 data input : STRINGTABLE DISCARDABLE LANG LANG_TAG LANG_TAG input : STRINGTABLE DISCARDABLE LANG input : STRINGTABLE LANG LANG_TAG LANG_TAG input : STRINGTABLE output : DISCARDABLE output : DISCARDABLE output : output : param : output_resid = empty param : output_text = DIALOG DISCARDABLE 15, 13, 210, 63 LANG LANG_TAG LANG_TAG param : text = type example DIALOG param : output_format = xml data store buffer */ void ParserCMD3(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format) { long foundPos=0; stringbugs(output_resid,false); stringbugs(output_text,false); find_str2 (" ",output_text,&foundPos,output_resid,output_text); trim(output_resid); trim(output_text); if(strncmp("STRINGTABLE",output_text,11)) sprintf(output_format,"%s\n DISCARDABLE\n",output_format,output_text,output_resid); else sprintf(output_format,"%s\n \n",output_format,output_resid,output_text); } /* ParserLang data input : LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US input : LANGUAGE LANG_ENGLISH SUBLANG_ENGLISH_US output : lang output : lang param : output_resid = not in use param : output_text = LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US param : text = type example LANGUAGE param : output_format = xml data store buffer */ void ParserLang(unsigned char *text, unsigned char *output_resid, unsigned char *output_text, unsigned char *output_format) { long foundPos=0; stringbugs(output_resid,false); stringbugs(output_text,false); sprintf(output_text,"%s",&output_text[strlen(text)+1]); /* split the lang into two string */ find_str2 (" ",output_text,&foundPos,output_resid,output_text); trim(output_resid); trim(output_text); sprintf(output_format,"%s\n %s\n\n",output_format,text,text,output_text,output_resid); } /* ParserComment data input : / * sadasdas asdasd asdas ... * / output : input : / * sadasdas asdasd asdas ... * / output : input : #if x output : input : // hi output : param : pos = current buf position param : buf = read in buffer from file rc param : buf_size = buf max size param : output_text = using internal instead alloc more memory param : output_resid = using internal instead alloc more memory param : output_format = xml data store buffer */ void ParserComment(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format) { long foundPos=0; long foundNextPos=0; long row_size=0; unsigned char *row = output_text; row_size = strlen(row); if (strncmp("//",&row[0],2)==0) { sprintf(output_format,"%s\n \n\n",output_format,row); return; } if (strncmp("#",&row[0],1)==0) { sprintf(output_format,"%s\n \n\n",output_format,row); return; } for (foundNextPos=0;foundNextPos\n \n\n",output_format,row); return; } } sprintf(output_format,"%s\n =2) { row[row_size -1]=0; } } else { row_size = buf_size - *pos; /* no new row found in the buffer */ strncpy(row, &buf[*pos], buf_size - *pos); *pos= buf_size; } /* Search now after end of comment */ row_size=strlen(row); for (foundNextPos=0;foundNextPos\n\n",output_format,row); return; } } sprintf(output_format,"%s%s\n",output_format,row); } } /* ParserAccelerators data input : BEGIN input : "^A", CMD_SELECT_ALL input : END output : output : output : param : pos = current buf position param : buf = read in buffer from file rc param : buf_size = buf max size param : output_text = using internal instead alloc more memory param : output_resid = using internal instead alloc more memory param : output_format = xml data store buffer */ void ParserAccelerators(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format) { long foundPos=0; long foundNextPos=0; long row_size=0; char *row = output_text; int start=false; long le; while(*pos < buf_size) { foundPos=0; row_size=0; /* create a row string so we can easy scan it */ find_str('\n',&buf[*pos],&foundPos); if (foundPos !=0) { row_size = foundPos - 1; /* found a new row */ strncpy(row, &buf[*pos], foundPos); *pos+=foundPos; if (foundPos >=2) { row[row_size -1]=0; } } else { row_size = buf_size - *pos; /* no new row found in the buffer */ strncpy(row, &buf[*pos], buf_size - *pos); *pos= buf_size; } stringbugs(row,true); if (start == false) { if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0)) { start=true; sprintf(output_format,"%s \n",output_format); } continue; } if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0)) { sprintf(output_format,"%s \n\n",output_format); *output_resid = '\0'; break; } foundPos=0; foundNextPos=0; find_str('"',row,&foundPos); find_str('"',&row[foundPos],&foundNextPos); if ((foundPos!=0) && (foundNextPos!=0)) { sprintf(output_format,"%s \n",output_format,row); } } } /* ParserString data input : BEGIN input : IDS_HINT_BLANK "text" input : END output : output : text output : param : pos = current buf position param : buf = read in buffer from file rc param : buf_size = buf max size param : output_text = using internal instead alloc more memory param : output_resid = using internal instead alloc more memory param : output_format = xml data store buffer */ void ParserString(long *pos, unsigned char *buf, long buf_size, unsigned char * output_text, unsigned char * output_resid, unsigned char * output_format) { long foundPos=0; long row_size=0; unsigned char *row = output_text; int start=false; while(*pos < buf_size) { foundPos=0; row_size=0; /* create a row string so we can easy scan it */ find_str('\n',&buf[*pos],&foundPos); if (foundPos !=0) { row_size = foundPos - 1; /* found a new row */ strncpy(row, &buf[*pos], foundPos); *pos+=foundPos; if (foundPos >=2) { row[row_size -1]=0; } } else { row_size = buf_size - *pos; /* no new row found in the buffer */ strncpy(row, &buf[*pos], buf_size - *pos); *pos= buf_size; } stringbugs(row,true); if (start == false) { if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0)) { start=true; sprintf(output_format,"%s \n",output_format); } continue; } if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0)) { sprintf(output_format,"%s \n\n",output_format); *output_resid = '\0'; break; } /* the split code here */ foundPos=0; find_str2 (" ",row,&foundPos,output_resid,output_text); if (foundPos != 0) { trim(output_text); trim(output_resid); if (*output_resid!='\0') sprintf(output_format,"%s \n",output_format,output_resid,output_text); else sprintf(output_format,"%s \n",output_format,output_resid); } } } /* ParserDialog data input : BEGIN output : output : input : END output : output : input : { output : output : input : } output : output : input : FONT 8, "MS Shell Dlg" output : input : FONT 8, "MS Shell Dlg", 0, 0, 0x1 output : 0 0 0x1 input : CONTROL "",101,"Static",SS_SIMPLE | SS_NOPREFIX,3,6,150,10 output : Builder1 input : DEFPUSHBUTTON "&OK",1,158,6,47,14 xx input : PUSHBUTTON "&Cancel",2,158,23,47,14 xx input : LTEXT "&Tooltip Text:",IDC_LABEL1,7,44,40,8 xx input : GROUPBOX "&Display Mode",IDC_LABEL4,7,96,157,28 xx input : ICON "",IDC_PICTURE,173,101,21,20 xx input : EDITTEXT 201,3,29,134,12,ES_AUTOHSCROLL input : LISTBOX IDC_LIST, 4, 16, 104, 46, WS_TABSTOP input : COMBOBOX ID_EOLN,54,18,156,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP output : output : output : output : builder2 input : CAPTION "Execute" input : EXSTYLE WS_EX_APPWINDOW input : STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU output : DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU param : pos = current buf position param : buf = read in buffer from file rc param : buf_size = buf max size param : output_text = using internal instead alloc more memory param : output_resid = using internal instead alloc more memory param : output_format = xml data store buffer */ 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) { long foundPos=0; long foundNextPos=0; long row_size=0; unsigned char *row = output_text; long commandfound=0; long le; *output_resid='\0'; le=0; while(*pos < buf_size) { foundPos=0; row_size=0; /* create a row string so we can easy scan it */ find_str('\n',&buf[*pos],&foundPos); if (foundPos !=0) { row_size = foundPos - 1; /* found a new row */ strncpy(row, &buf[*pos], foundPos); *pos+=foundPos; if (foundPos >=2) { row[row_size -1]=0; } } else { row_size = buf_size - *pos; /* no new row found in the buffer */ strncpy(row, &buf[*pos], buf_size - *pos); *pos= buf_size; } //stringbugs(row,true); trim(row); if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0)) commandfound=1; if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0)) commandfound=2; if (strncmp("STYLE ",row,6)==0) commandfound=3; if (strncmp("CAPTION ",row,8)==0) commandfound=3; if (strncmp("FONT ",row,5)==0) commandfound=3; if (strncmp("CONTROL ",row,8)==0) commandfound=3; if (strncmp("EDITTEXT ",row,9)==0) commandfound=3; if (strncmp("DEFPUSHBUTTON ",row,14)==0) commandfound=3; if (strncmp("PUSHBUTTON ",row,11)==0) commandfound=3; if (strncmp("LTEXT ",row,6)==0) commandfound=3; if (strncmp("GROUPBOX ",row,9)==0) commandfound=3; if (strncmp("ICON ",row,5)==0) commandfound=3; if (strncmp("EXSTYLE ",row,8)==0) commandfound=3; if (strncmp(row,"LISTBOX ",8)==0) commandfound=3; if (strncmp(row,"COMBOBOX ",9)==0) commandfound=3; if ((*output_resid!=0) && (commandfound!=0)) { /* Builder 1*/ if (strncmp(output_resid,"LTEXT ",6)==0) DialogCMDBuild1(output_resid, output_format, 5, "LTEXT"); if (strncmp(output_resid,"GROUPBOX ",9)==0) DialogCMDBuild1(output_resid, output_format, 8, "GROUPBOX"); if (strncmp(output_resid,"DEFPUSHBUTTON ",14)==0) DialogCMDBuild1(output_resid, output_format, 13, "DEFPUSHBUTTON"); if (strncmp(output_resid,"PUSHBUTTON ",11)==0) DialogCMDBuild1(output_resid, output_format, 10, "PUSHBUTTON"); if (strncmp("ICON ",output_resid,5)==0) DialogCMDBuild1(output_resid, output_format, 4, "ICON"); if (strncmp("EDITTEXT ",output_resid,9)==0) DialogCMDBuild1(output_resid, output_format, 8, "EDITTEXT"); if (strncmp("LISTBOX ",output_resid,8)==0) DialogCMDBuild1(output_resid, output_format, 7, "LISTBOX"); if (strncmp("COMBOBOX ",output_resid,9)==0) DialogCMDBuild1(output_resid, output_format, 8, "COMBOBOX"); /* Builder 2*/ if (strncmp("STYLE ",output_resid,6)==0) DialogCMDBuild2(output_resid, output_format, 5, "STYLE"); if (strncmp("EXSTYLE ",output_resid,8)==0) DialogCMDBuild2(output_resid, output_format, 7, "EXSTYLE"); if (strncmp("CAPTION ",output_resid,8)==0) DialogCMDBuild2(output_resid, output_format, 7, "CAPTION"); if (strncmp("CONTROL ",output_resid,8)==0) DialogCMDBuild3(output_resid, output_format, 7, "CONTROL"); /* no builder */ if (strncmp(output_resid,"FONT ",5)==0) { stringbugs(output_resid,true); /* FONT */ sprintf(output_resid,"%s",&output_resid[5]); trim(output_resid); sprintf(output_format,"%s \n",output_format); } else { sprintf(output_format,"%s\">%s\n",output_format,&output_resid[foundPos]); } *output_resid=0; } *output_resid='\0'; } if (commandfound==1) { sprintf(output_format,"%s \n",output_format,text); } if (commandfound==2) { sprintf(output_format,"%s \n\n",output_format,text); break; } sprintf(output_resid,"%s%s",output_resid,row); commandfound=0; } } ////////////////////////// /* ParserDialog data input : BEGIN output : output : input : END output : output : input : { output : output : input : } output : output : param : pos = current buf position param : buf = read in buffer from file rc param : buf_size = buf max size param : output_text = using internal instead alloc more memory param : output_resid = using internal instead alloc more memory param : output_format = xml data store buffer */ 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) { long foundPos=0; long foundNextPos=0; long row_size=0; unsigned char *row = output_text; long commandfound=0; long le; long count=0; *output_resid='\0'; le=0; while(*pos < buf_size) { foundPos=0; row_size=0; /* create a row string so we can easy scan it */ find_str('\n',&buf[*pos],&foundPos); if (foundPos !=0) { row_size = foundPos - 1; /* found a new row */ strncpy(row, &buf[*pos], foundPos); *pos+=foundPos; if (foundPos >=2) { row[row_size -1]=0; } } else { row_size = buf_size - *pos; /* no new row found in the buffer */ strncpy(row, &buf[*pos], buf_size - *pos); *pos= buf_size; } //stringbugs(row,true); stringbugs2(row,true); if ((strcmp(row,"BEGIN")==0) || (strcmp(row,"{")==0)) commandfound=1; if ((strcmp(row,"END")==0) || (strcmp(row,"}")==0)) commandfound=2; if (strncmp("POPUP ",row,6)==0) commandfound=3; if (strncmp("MENUITEM ",row,8)==0) commandfound=3; if ((*output_resid!=0) && (commandfound!=0)) { if (strncmp(output_resid,"POPUP ",6)==0) { sprintf(output_resid,"%s",&output_resid[5]); trim(output_resid); sprintf(output_format,"%s\n",output_format,output_resid); *output_resid='\0'; } if (strncmp(output_resid,"MENUITEM ",9)==0) { sprintf(output_resid,"%s",&output_resid[8]); trim(output_resid); if (strcmp(output_resid,"SEPARATOR")==0) { sprintf(output_format,"%s\n",output_format); *output_resid='\0'; } else { foundPos=0; foundNextPos=0; find_str('"',output_resid,&foundPos); find_str('"',&output_resid[foundPos],&foundNextPos); stringbugs(&output_resid[foundPos+foundNextPos],true); if ((foundPos+foundNextPos)==0) { sprintf(output_format,"%s\n",output_format,&output_resid[foundPos+foundNextPos]); } else { sprintf(output_format,"%s",output_format,&output_resid[foundPos+foundNextPos]); output_resid[foundPos+foundNextPos]='\0'; trim(output_resid); sprintf(output_format,"%s\n",output_format,output_resid); } *output_resid='\0'; } } *output_resid='\0'; } if (commandfound==1) { count++; if (count==1) sprintf(output_format,"%s\n",output_format,text); else sprintf(output_format,"%s\n",output_format); *output_resid='\0'; } if (commandfound==2) { count--; *output_resid='\0'; if (count<1) sprintf(output_format,"%s\n",output_format,text); else sprintf(output_format,"%s\n",output_format); if (count<1) { sprintf(output_format,"%s\n",output_format); break; } } sprintf(output_resid,"%s%s",output_resid,row); commandfound=0; } } void stringbugs(unsigned char *buf, int shift2) { long foundPos=0; long foundNextPos=0; long t=0; /* remove , */ if (shift2== false) { for (t=0;t0) { if (isspace(buf[le-1])!=0) { buf[le-1]=0; le=strlen(buf); } else { break; } } le=strlen(buf); while(le>0) { if (isspace(buf[0])!=0) { strncpy(&buf[0],&buf[1],le-1); buf[le-1]=0; le=strlen(buf); } else { break; } } } void find_str(unsigned char asc,unsigned char *buf, long *foundPos) { int t; size_t le; le=strlen(buf); for (t=0;t\n",output_format,output_resid); } else { sprintf(output_format,"%s\">\n",output_format); } } else { if (*output_resid!='\0') sprintf(output_format,"%s\" style=\"\">\n",output_format,output_resid); else sprintf(output_format,"%s\" style=\"\">\n",output_format); } *output_resid='\0'; } void DialogCMDBuild2(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text) { long le; stringbugs(output_resid,true); sprintf(output_resid,"%s",&output_resid[pos]); trim(output_resid); le = strlen(output_resid); if (*output_resid=='"') *output_resid=' '; if (output_resid[le-1]=='"') output_resid[le-1]=' '; trim(output_resid); sprintf(output_format,"%s \n",output_format,text,output_resid); *output_resid='\0'; } // input : CONTROL "",101,"Static",SS_SIMPLE | SS_NOPREFIX,3,6,150,10 void DialogCMDBuild3(unsigned char *output_resid, unsigned char *output_format, long pos, unsigned char * text) { long foundPos=0; long foundNextPos=0; long le; long count=0; long save1; long save2; sprintf(output_resid,"%s",&output_resid[pos]); trim(output_resid); find_str('"',output_resid,&foundPos); find_str('"',&output_resid[foundPos],&foundNextPos); save1=foundPos; save2=foundNextPos; sprintf(output_format,"%s \n",output_format,output_resid); else sprintf(output_format,"%s\">\n",output_format); *output_resid='\0'; }