Leaked source code of windows server 2003
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.

126 lines
3.0 KiB

  1. /*
  2. * mksjuni - Convert SJIS code to Unicode.
  3. * (derived from mkunitab.c - Convert JIS code to Unicode.)
  4. *
  5. * TODO:
  6. *
  7. * HISTORY:
  8. *
  9. * 9/4/98 yasuho Created.
  10. */
  11. #include <stdio.h>
  12. #include <stddef.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <windef.h>
  16. #include <winbase.h>
  17. #include <winnls.h>
  18. static char buf[256];
  19. static void mkunitab(char *name);
  20. static void jis2sjis(BYTE jis[], BYTE sjis[]);
  21. static void usage();
  22. static void fatal(char *s);
  23. static void error(char *s);
  24. void __cdecl main(int argc, char *argv[])
  25. {
  26. argc--, argv++;
  27. if (argc == 0)
  28. usage();
  29. while (argc--)
  30. mkunitab(*argv++);
  31. exit(0);
  32. }
  33. static void mkunitab(char *name)
  34. {
  35. BYTE jis[2];
  36. BYTE sjis[4];
  37. WORD v, n, len;
  38. INT v1, v2;
  39. WCHAR uni[2];
  40. FILE *fp;
  41. if ((fp = fopen(name, "r")) == NULL)
  42. fatal(name);
  43. while (fgets(buf, sizeof buf, fp)) {
  44. len = strlen(buf);
  45. n = 0;
  46. while (isxdigit(buf[n]))
  47. n++;
  48. if (n == 0)
  49. continue;
  50. if (n != 2 && n != 4)
  51. error("Invalid format");
  52. if (sscanf(buf, "%x %d %d", &v, &v1, &v2) != 3)
  53. error("Invalid format");
  54. // SBCS Vertical font doesn't lying
  55. if (v <= 0xFF)
  56. v2 = -v1;
  57. // source file is sjis v-masatk @Oct/26/98 ->
  58. // jis[0] = HIBYTE(v);
  59. // jis[1] = LOBYTE(v);
  60. // jis2sjis(jis, sjis);
  61. sjis[0] = HIBYTE(v);
  62. sjis[1] = LOBYTE(v);
  63. // <-
  64. sjis[2] = 0;
  65. if (!MultiByteToWideChar(CP_ACP, 0, (const char *)sjis, 2,
  66. uni, sizeof uni))
  67. error("MultiByteToWideChar: fail");
  68. printf("%04x%8d%8d\n", uni[0], v1, v2);
  69. }
  70. fclose(fp);
  71. }
  72. static void jis2sjis(BYTE jis[], BYTE sjis[])
  73. {
  74. BYTE h, l;
  75. h = jis[0];
  76. l = jis[1];
  77. if (h == 0) {
  78. sjis[0] = l;
  79. sjis[1] = 0;
  80. return;
  81. }
  82. l += 0x1F;
  83. if (h & 0x01)
  84. h >>= 1;
  85. else {
  86. h >>= 1;
  87. l += 0x5E;
  88. h--;
  89. }
  90. if (l >= 0x7F)
  91. l++;
  92. if (h < 0x2F)
  93. h += 0x71;
  94. else
  95. h += 0xB1;
  96. sjis[0] = h;
  97. sjis[1] = l;
  98. }
  99. static void usage()
  100. {
  101. fprintf(stderr, "Usage: mkunitab file[...]\n");
  102. exit(1);
  103. }
  104. static void fatal(char *s)
  105. {
  106. fprintf(stderr, "mkunitab: ");
  107. perror(s);
  108. exit(1);
  109. }
  110. static void error(char *s)
  111. {
  112. fprintf(stderr, "mkunitab: %s\n", s);
  113. exit(1);
  114. }