Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. // Ajout pour LC_TEXT_EN
  2. void locale_init2(const char* filename)
  3. {
  4. FILE* fp = fopen(filename, "rb");
  5. char* buf;
  6.  
  7. if (!fp) return;
  8.  
  9. fseek(fp, 0L, SEEK_END);
  10. int i = ftell(fp);
  11. fseek(fp, 0L, SEEK_SET);
  12.  
  13. i++;
  14.  
  15. buf = M2_NEW char[i];
  16.  
  17. memset(buf, 0, i);
  18.  
  19. fread(buf, i - 1, sizeof(char), fp);
  20.  
  21. fclose(fp);
  22.  
  23. const char* tmp;
  24. const char* end;
  25.  
  26. char* strings[NUM_LOCALES];
  27.  
  28. if (!buf)
  29. {
  30. sys_err("locale_read: no file %s", filename);
  31. exit(1);
  32. }
  33.  
  34. tmp = buf;
  35.  
  36. do
  37. {
  38. for (i = 0; i < NUM_LOCALES; i++)
  39. strings[i] = NULL;
  40.  
  41. if (*tmp == '"')
  42. {
  43. for (i = 0; i < NUM_LOCALES; i++)
  44. {
  45. if (!(end = quote_find_end(tmp)))
  46. break;
  47.  
  48. strings[i] = locale_convert(tmp, end - tmp);
  49. tmp = ++end;
  50.  
  51. while (*tmp == '\n' || *tmp == '\r' || *tmp == ' ') tmp++;
  52.  
  53. if (i + 1 == NUM_LOCALES)
  54. break;
  55.  
  56. if (*tmp != '"')
  57. {
  58. sys_err("locale_init: invalid format filename %s", filename);
  59. break;
  60. }
  61. }
  62.  
  63. if (strings[0] == NULL || strings[1] == NULL)
  64. break;
  65.  
  66. locale_add((const char**)strings);
  67.  
  68. for (i = 0; i < NUM_LOCALES; i++)
  69. if (strings[i])
  70. M2_DELETE_ARRAY(strings[i]);
  71. }
  72. else
  73. {
  74. tmp = strchr(tmp, '\n');
  75.  
  76. if (tmp)
  77. tmp++;
  78. }
  79. } while (tmp && *tmp);
  80.  
  81. M2_DELETE_ARRAY(buf);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement