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.

216 lines
6.1 KiB

  1. /****************************************************************************
  2. PROGRAM: MkUni.c
  3. PURPOSE: Creates a text file with unicode characters
  4. FUNCTIONS:
  5. ****************************************************************************/
  6. #include <windows.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <tchar.h>
  10. #include "mkuni.h"
  11. #define REVERSE 0
  12. #define LINE_SIZE 1000
  13. #define ASCIIEOL TEXT("\r\n")
  14. #define UNILINESEP 0x2028
  15. #define UNIPARASEP 0x2029
  16. struct __range {
  17. int low;
  18. int high;
  19. LPTSTR pDes;
  20. } range[] = {
  21. {0x20, 0x7f, TEXT("ANSI") },
  22. {0xa0, 0xff, TEXT("Latin") },
  23. {0x100, 0x17f, TEXT("European Latin") },
  24. {0x180, 0x1f0, TEXT("Extended Latin") },
  25. {0x250, 0x2a8, TEXT("Standard Phonetic") },
  26. {0x2b0, 0x2e9, TEXT("Modifier Letters") },
  27. {0x300, 0x341, TEXT("Generic Diacritical") },
  28. {0x370, 0x3f5, TEXT("Greek") },
  29. {0x400, 0x486, TEXT("Cyrillic") },
  30. {0x490, 0x4cc, TEXT("Extended Cyrillic") },
  31. {0x5b0, 0x5f5, TEXT("Hebrew") },
  32. {0x0600,0x06F9, TEXT("Arabic") },
  33. {0x0900,0x0970, TEXT("Devanagari") },
  34. {0x0E00,0x0E5B, TEXT("Thai") },
  35. {0x1000,0x104C, TEXT("Tibetan") },
  36. {0x10A0,0x10FB, TEXT("Georgian") },
  37. {0x20a0,0x20aa, TEXT("Currency Symbols") },
  38. {0x2100,0x2138, TEXT("Letterlike Symbols") },
  39. {0x2153,0x2182, TEXT("Number Forms") },
  40. {0x2190,0x21ea, TEXT("Arrows") },
  41. {0x2200,0x22f1, TEXT("Math Operators") },
  42. {0x2500,0x257F, TEXT("Form and Chart Components") },
  43. {0x25A0,0x25EE, TEXT("Geometric Shapes") },
  44. {0x2600,0x266F, TEXT("Miscellaneous Dingbats") },
  45. {0x3000,0x303F, TEXT("CJK Symbols and Punctuations") },
  46. {0x3040,0x309E, TEXT("Hiragana") },
  47. {0x3100,0x312C, TEXT("Bopomofo") },
  48. {0x3131,0x318E, TEXT("Hangul Elements") },
  49. {0, 0, TEXT("terminating entry") },
  50. };
  51. /****************************************************************************
  52. FUNCTION: putu(FILE*pf, TCHAR c)
  53. PURPOSE: writes a character to the file.
  54. (Reverses the order of leadbytes if the flag is set)
  55. ****************************************************************************/
  56. void
  57. putu(FILE*pf, TCHAR c)
  58. {
  59. TCHAR chr=c;
  60. if( REVERSE )
  61. chr= ( c<<8 ) + ( ( c>>8 ) &0xFF);
  62. fwrite((void*)&chr, 1, sizeof(TCHAR), pf);
  63. }
  64. /****************************************************************************
  65. FUNCTION: putust(FILE*pf, LPTSTR pc)
  66. PURPOSE: writes a string to the file.
  67. ****************************************************************************/
  68. void
  69. putust(FILE*pf, LPTSTR pc)
  70. {
  71. while (*pc)
  72. putu(pf, *pc++);
  73. }
  74. /****************************************************************************
  75. FUNCTION: main(int, char**)
  76. PURPOSE: write sample unicode file
  77. ****************************************************************************/
  78. int _cdecl main(int argc, char**argv)
  79. {
  80. struct __range*pr = range;
  81. int i;
  82. FILE *pf;
  83. FILE *pfo;
  84. char lpstrLine[LINE_SIZE];
  85. if(!(pf = fopen("unicode.txt", "wb")))
  86. return FALSE;
  87. // Task1: Write all the unicode ranges and all the characters
  88. // in those ranges to the output file.
  89. putu(pf, (TCHAR)0xfeff);
  90. while (pr->low != 0) {
  91. putust(pf, TEXT("<<< "));
  92. putust(pf, pr->pDes);
  93. putust(pf, TEXT(" >>>"));
  94. putust(pf, ASCIIEOL );
  95. for (i=pr->low ; i<=pr->high ; i++)
  96. putu(pf, (TCHAR)i);
  97. putust(pf, ASCIIEOL);
  98. pr++;
  99. }
  100. putust(pf, TEXT("Unicode Line separator here ->"));
  101. putu(pf, UNILINESEP );
  102. putust(pf, TEXT("<- Unicode line separator"));
  103. putust( pf, ASCIIEOL );
  104. putust(pf, TEXT("Unicode Paragraph separator here ->"));
  105. putu(pf, UNIPARASEP );
  106. putust(pf, TEXT("<- Unicode paragraph separator"));
  107. putust( pf, ASCIIEOL );
  108. fclose( pf );
  109. // Task2: Write all the characters codes and information
  110. // on each character code to an output file.
  111. if (!(pf = fopen( "names2.txt", "r" )))
  112. return FALSE;
  113. if (!(pfo = fopen("unicodes.txt", "wb")))
  114. return FALSE;
  115. // The first character should be 0xFEFF in the file,
  116. // indicating that it's an unicode file.
  117. putu( pfo, (TCHAR)0xfeff);
  118. // Read the input file (names2.txt) which has information
  119. // on every unicode character.
  120. do
  121. {
  122. WCHAR wLineBuffer[LINE_SIZE];
  123. int i, num;
  124. if (!memset(lpstrLine, 0, LINE_SIZE))
  125. {
  126. _tprintf(TEXT("Something wrong - failed in Memset!!\n") );
  127. break;
  128. }
  129. // fgets returns NULL on eof or on an error condition
  130. if( fgets( lpstrLine, LINE_SIZE, pf) == NULL )
  131. {
  132. if (!feof(pf))
  133. _tprintf(TEXT("Error occured while reading names2.txt.\n") );
  134. break;
  135. }
  136. i = 0;
  137. // Find the first newline (if there is any) and replace it by \0.
  138. while((lpstrLine[i]!= '\n') && (lpstrLine[i]!='\r') && (lpstrLine[i]!='\0'))
  139. {
  140. i++;
  141. }
  142. lpstrLine[i]= '\0';
  143. // If the line has the character code (for which info is given)
  144. // grab and "display" that.
  145. num= -1;
  146. sscanf( lpstrLine, "%x", &num);
  147. if( num != -1 )
  148. {
  149. putu( pfo, (TCHAR) num );
  150. putust( pfo, TEXT(": ") );
  151. }
  152. else
  153. {
  154. putust( pfo,TEXT(" ") );
  155. }
  156. // Convert it to the world of unicodes.
  157. if (MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, lpstrLine, -1,
  158. wLineBuffer, LINE_SIZE ))
  159. putust(pfo, wLineBuffer);
  160. putust( pfo, ASCIIEOL );
  161. }
  162. while( TRUE );
  163. fclose( pfo );
  164. fclose( pf );
  165. return 1;
  166. }