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.

74 lines
1.3 KiB

  1. #include <stdio.h>
  2. #include <string.h>
  3. static void print_short_array(unsigned short *a, size_t width)
  4. {
  5. int i;
  6. printf("{\n");
  7. for (i=0; i<=0xFF; i++)
  8. {
  9. const char *fmt= (width==4) ? "0x%04X" : "0x%02X";
  10. printf(fmt,(int)a[i]);
  11. printf("%s%s",i<0xFF?",":"",(i+1) % 8 ? "" :"\n");
  12. }
  13. printf("};\n");
  14. }
  15. int main(void)
  16. {
  17. char str[160];
  18. unsigned short touni[256];
  19. unsigned short fromuni[65536];
  20. unsigned short fromstat[256];
  21. int i;
  22. bzero((void*)touni,sizeof(touni));
  23. bzero((void*)fromuni,sizeof(fromuni));
  24. bzero((void*)fromstat,sizeof(fromstat));
  25. while (fgets(str,sizeof(str),stdin))
  26. {
  27. unsigned int c,u;
  28. if ((str[0]=='#') || (2!=sscanf(str,"%x%x",&c,&u)))
  29. continue;
  30. if (c>0xFF || u>0xFFFF)
  31. continue;
  32. touni[c]= u;
  33. fromuni[u]= c;
  34. }
  35. printf("unsigned short cs_to_uni[256]=");
  36. print_short_array(touni, 4);
  37. for (i=0;i<=0xFF;i++)
  38. {
  39. fromstat[touni[i]>>8]++;
  40. }
  41. for (i=0;i<=256;i++)
  42. {
  43. if (fromstat[i])
  44. {
  45. printf("unsigned char pl%02X[256]=",i);
  46. print_short_array(fromuni+i*256, 2);
  47. }
  48. }
  49. printf("unsigned short *uni_to_cs[256]={\n");
  50. for (i=0;i<=255;i++)
  51. {
  52. if (fromstat[i])
  53. printf("pl%02X",i);
  54. else
  55. printf("NULL");
  56. printf("%s%s",i<255?",":"",((i+1) % 8) ? "":"\n");
  57. }
  58. printf("};\n");
  59. return 0;
  60. }