Advertisement
Guest User

Untitled

a guest
Apr 10th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #define STR_MAX 256
  4. #define FM_READ "r"
  5.  
  6. char **pPhrases;
  7.  
  8. int LoadLanguage(char *sFileName)
  9. {
  10. FILE *f;
  11. int nx, ny;
  12. char *eq,*pos2;
  13. char sLine[STR_MAX*2],sTemp[STR_MAX*2];
  14. static int inited=0;
  15. if(inited)
  16. return 0;
  17. inited=1;
  18. pPhrases=new char*[MAX_PHRASES];
  19. for(nx=0;nx<MAX_PHRASES;nx++)
  20. if(!(pPhrases[nx]=new char[STR_MAX]))
  21. return 1;
  22. if(!(f=fopen(sFileName,FM_READ)))
  23. return 2;
  24. for(nx=0;nx<MAX_PHRASES;nx++)
  25. {
  26. fgets(sLine,STR_MAX*2,f);
  27. sLine[strlen(sLine)-2]='\0';
  28. eq=strchr(sLine,'=');
  29. if(!eq)
  30. {
  31. nx--;
  32. continue;
  33. }
  34. ny=0;
  35. while(pos2=strstr(sLine,"\\n"))
  36. {
  37. *pos2='\r';
  38. *(pos2+1)='\n';
  39. }
  40. while(pos2=strstr(sLine+ny,"\\\\"))
  41. {
  42. if(pos2[2]!='\\')
  43. {
  44. strcpy(sTemp,pos2);
  45. strncpy(pos2,sTemp+1,strlen(pos2));
  46. }
  47. else
  48. ny=(int)pos2-(int)sLine+4;
  49.  
  50. }
  51. while(pos2=strstr(sLine,"\\\\\\\\"))
  52. {
  53. if(pos2[4]!='\\')
  54. {
  55. strcpy(sTemp,pos2);
  56. strncpy(pos2,sTemp+2,strlen(pos2));
  57. }
  58. }
  59. while(pos2=strstr(sLine,"\\\""))
  60. {
  61. strcpy(sTemp,pos2);
  62. strncpy(pos2,sTemp+1,strlen(pos2));
  63. }
  64. while(pos2=strstr(sLine,"\\\'"))
  65. {
  66. strcpy(sTemp,pos2);
  67. strncpy(pos2,sTemp+1,strlen(pos2));
  68. }
  69. while(pos2=strstr(sLine,"\\t"))
  70. {
  71. *(pos2+1)='\t';
  72. strcpy(sTemp,pos2);
  73. strncpy(pos2,sTemp+1,strlen(pos2));
  74. }
  75. strncpy(pPhrases[nx],eq+2,strlen(eq));
  76. pPhrases[nx][strlen(eq)-2]='\0';
  77. }
  78. fclose(f);
  79. return 0;
  80. }
  81.  
  82. void UnloadLanguage()
  83. {
  84. int nx;
  85. for(nx=0;nx<MAX_PHRASES;nx++)
  86. delete[](pPhrases[nx]);
  87. delete[]pPhrases;
  88. pPhrases=NULL;
  89. }
  90. char *tr(int nPhraseID)
  91. {
  92. if(pPhrases==NULL)
  93. return NULL;
  94. return pPhrases[nPhraseID];
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement