You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB

  1. /* Copyright (C) 2003-2004 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #include <stdio.h>
  13. #include <string.h>
  14. static void print_short_array(unsigned short *a, size_t width)
  15. {
  16. int i;
  17. printf("{\n");
  18. for (i=0; i<=0xFF; i++)
  19. {
  20. const char *fmt= (width==4) ? "0x%04X" : "0x%02X";
  21. printf(fmt,(int)a[i]);
  22. printf("%s%s",i<0xFF?",":"",(i+1) % 8 ? "" :"\n");
  23. }
  24. printf("};\n");
  25. }
  26. int main(void)
  27. {
  28. char str[160];
  29. unsigned short touni[256];
  30. unsigned short fromuni[65536];
  31. unsigned short fromstat[256];
  32. int i;
  33. bzero((void*)touni,sizeof(touni));
  34. bzero((void*)fromuni,sizeof(fromuni));
  35. bzero((void*)fromstat,sizeof(fromstat));
  36. while (fgets(str,sizeof(str),stdin))
  37. {
  38. unsigned int c,u;
  39. if ((str[0]=='#') || (2!=sscanf(str,"%x%x",&c,&u)))
  40. continue;
  41. if (c>0xFF || u>0xFFFF)
  42. continue;
  43. touni[c]= u;
  44. fromuni[u]= c;
  45. }
  46. printf("unsigned short cs_to_uni[256]=");
  47. print_short_array(touni, 4);
  48. for (i=0;i<=0xFF;i++)
  49. {
  50. fromstat[touni[i]>>8]++;
  51. }
  52. for (i=0;i<=256;i++)
  53. {
  54. if (fromstat[i])
  55. {
  56. printf("unsigned char pl%02X[256]=",i);
  57. print_short_array(fromuni+i*256, 2);
  58. }
  59. }
  60. printf("unsigned short *uni_to_cs[256]={\n");
  61. for (i=0;i<=255;i++)
  62. {
  63. if (fromstat[i])
  64. printf("pl%02X",i);
  65. else
  66. printf("NULL");
  67. printf("%s%s",i<255?",":"",((i+1) % 8) ? "":"\n");
  68. }
  69. printf("};\n");
  70. return 0;
  71. }