Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #define STR_MAX 256
- #define FM_READ "r"
- char **pPhrases;
- int LoadLanguage(char *sFileName)
- {
- FILE *f;
- int nx, ny;
- char *eq,*pos2;
- char sLine[STR_MAX*2],sTemp[STR_MAX*2];
- static int inited=0;
- if(inited)
- return 0;
- inited=1;
- pPhrases=new char*[MAX_PHRASES];
- for(nx=0;nx<MAX_PHRASES;nx++)
- if(!(pPhrases[nx]=new char[STR_MAX]))
- return 1;
- if(!(f=fopen(sFileName,FM_READ)))
- return 2;
- for(nx=0;nx<MAX_PHRASES;nx++)
- {
- fgets(sLine,STR_MAX*2,f);
- sLine[strlen(sLine)-2]='\0';
- eq=strchr(sLine,'=');
- if(!eq)
- {
- nx--;
- continue;
- }
- ny=0;
- while(pos2=strstr(sLine,"\\n"))
- {
- *pos2='\r';
- *(pos2+1)='\n';
- }
- while(pos2=strstr(sLine+ny,"\\\\"))
- {
- if(pos2[2]!='\\')
- {
- strcpy(sTemp,pos2);
- strncpy(pos2,sTemp+1,strlen(pos2));
- }
- else
- ny=(int)pos2-(int)sLine+4;
- }
- while(pos2=strstr(sLine,"\\\\\\\\"))
- {
- if(pos2[4]!='\\')
- {
- strcpy(sTemp,pos2);
- strncpy(pos2,sTemp+2,strlen(pos2));
- }
- }
- while(pos2=strstr(sLine,"\\\""))
- {
- strcpy(sTemp,pos2);
- strncpy(pos2,sTemp+1,strlen(pos2));
- }
- while(pos2=strstr(sLine,"\\\'"))
- {
- strcpy(sTemp,pos2);
- strncpy(pos2,sTemp+1,strlen(pos2));
- }
- while(pos2=strstr(sLine,"\\t"))
- {
- *(pos2+1)='\t';
- strcpy(sTemp,pos2);
- strncpy(pos2,sTemp+1,strlen(pos2));
- }
- strncpy(pPhrases[nx],eq+2,strlen(eq));
- pPhrases[nx][strlen(eq)-2]='\0';
- }
- fclose(f);
- return 0;
- }
- void UnloadLanguage()
- {
- int nx;
- for(nx=0;nx<MAX_PHRASES;nx++)
- delete[](pPhrases[nx]);
- delete[]pPhrases;
- pPhrases=NULL;
- }
- char *tr(int nPhraseID)
- {
- if(pPhrases==NULL)
- return NULL;
- return pPhrases[nPhraseID];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement