upcase.c 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * upcase.c - Generate the full NTFS Unicode upcase table in little endian.
  3. * Part of the Linux-NTFS project.
  4. *
  5. * Copyright (c) 2001 Richard Russon <ntfs@flatcap.org>
  6. * Copyright (c) 2001-2006 Anton Altaparmakov
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program (in the main directory of the Linux-NTFS source
  20. * in the file COPYING); if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include "malloc.h"
  24. #include "ntfs.h"
  25. ntfschar *generate_default_upcase(void)
  26. {
  27. static const int uc_run_table[][3] = { /* Start, End, Add */
  28. {0x0061, 0x007B, -32}, {0x0451, 0x045D, -80}, {0x1F70, 0x1F72, 74},
  29. {0x00E0, 0x00F7, -32}, {0x045E, 0x0460, -80}, {0x1F72, 0x1F76, 86},
  30. {0x00F8, 0x00FF, -32}, {0x0561, 0x0587, -48}, {0x1F76, 0x1F78, 100},
  31. {0x0256, 0x0258, -205}, {0x1F00, 0x1F08, 8}, {0x1F78, 0x1F7A, 128},
  32. {0x028A, 0x028C, -217}, {0x1F10, 0x1F16, 8}, {0x1F7A, 0x1F7C, 112},
  33. {0x03AC, 0x03AD, -38}, {0x1F20, 0x1F28, 8}, {0x1F7C, 0x1F7E, 126},
  34. {0x03AD, 0x03B0, -37}, {0x1F30, 0x1F38, 8}, {0x1FB0, 0x1FB2, 8},
  35. {0x03B1, 0x03C2, -32}, {0x1F40, 0x1F46, 8}, {0x1FD0, 0x1FD2, 8},
  36. {0x03C2, 0x03C3, -31}, {0x1F51, 0x1F52, 8}, {0x1FE0, 0x1FE2, 8},
  37. {0x03C3, 0x03CC, -32}, {0x1F53, 0x1F54, 8}, {0x1FE5, 0x1FE6, 7},
  38. {0x03CC, 0x03CD, -64}, {0x1F55, 0x1F56, 8}, {0x2170, 0x2180, -16},
  39. {0x03CD, 0x03CF, -63}, {0x1F57, 0x1F58, 8}, {0x24D0, 0x24EA, -26},
  40. {0x0430, 0x0450, -32}, {0x1F60, 0x1F68, 8}, {0xFF41, 0xFF5B, -32},
  41. {0}
  42. };
  43. static const int uc_dup_table[][2] = { /* Start, End */
  44. {0x0100, 0x012F}, {0x01A0, 0x01A6}, {0x03E2, 0x03EF}, {0x04CB, 0x04CC},
  45. {0x0132, 0x0137}, {0x01B3, 0x01B7}, {0x0460, 0x0481}, {0x04D0, 0x04EB},
  46. {0x0139, 0x0149}, {0x01CD, 0x01DD}, {0x0490, 0x04BF}, {0x04EE, 0x04F5},
  47. {0x014A, 0x0178}, {0x01DE, 0x01EF}, {0x04BF, 0x04BF}, {0x04F8, 0x04F9},
  48. {0x0179, 0x017E}, {0x01F4, 0x01F5}, {0x04C1, 0x04C4}, {0x1E00, 0x1E95},
  49. {0x018B, 0x018B}, {0x01FA, 0x0218}, {0x04C7, 0x04C8}, {0x1EA0, 0x1EF9},
  50. {0}
  51. };
  52. static const int uc_word_table[][2] = { /* Offset, Value */
  53. {0x00FF, 0x0178}, {0x01AD, 0x01AC}, {0x01F3, 0x01F1}, {0x0269, 0x0196},
  54. {0x0183, 0x0182}, {0x01B0, 0x01AF}, {0x0253, 0x0181}, {0x026F, 0x019C},
  55. {0x0185, 0x0184}, {0x01B9, 0x01B8}, {0x0254, 0x0186}, {0x0272, 0x019D},
  56. {0x0188, 0x0187}, {0x01BD, 0x01BC}, {0x0259, 0x018F}, {0x0275, 0x019F},
  57. {0x018C, 0x018B}, {0x01C6, 0x01C4}, {0x025B, 0x0190}, {0x0283, 0x01A9},
  58. {0x0192, 0x0191}, {0x01C9, 0x01C7}, {0x0260, 0x0193}, {0x0288, 0x01AE},
  59. {0x0199, 0x0198}, {0x01CC, 0x01CA}, {0x0263, 0x0194}, {0x0292, 0x01B7},
  60. {0x01A8, 0x01A7}, {0x01DD, 0x018E}, {0x0268, 0x0197},
  61. {0}
  62. };
  63. int i, r;
  64. ntfschar *uc;
  65. uc = ntfs_malloc_nofs(default_upcase_len * sizeof(ntfschar));
  66. if (!uc)
  67. return uc;
  68. memset(uc, 0, default_upcase_len * sizeof(ntfschar));
  69. /* Generate the little endian Unicode upcase table used by ntfs. */
  70. for (i = 0; i < default_upcase_len; i++)
  71. uc[i] = cpu_to_le16(i);
  72. for (r = 0; uc_run_table[r][0]; r++)
  73. for (i = uc_run_table[r][0]; i < uc_run_table[r][1]; i++)
  74. uc[i] = cpu_to_le16(le16_to_cpu(uc[i]) +
  75. uc_run_table[r][2]);
  76. for (r = 0; uc_dup_table[r][0]; r++)
  77. for (i = uc_dup_table[r][0]; i < uc_dup_table[r][1]; i += 2)
  78. uc[i + 1] = cpu_to_le16(le16_to_cpu(uc[i + 1]) - 1);
  79. for (r = 0; uc_word_table[r][0]; r++)
  80. uc[uc_word_table[r][0]] = cpu_to_le16(uc_word_table[r][1]);
  81. return uc;
  82. }