Source code of Windows XP (NT5)
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.

179 lines
4.8 KiB

  1. //
  2. // ���C ���y ���X�{��
  3. //
  4. // ���Ż� 1998/03/15
  5. //
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include "resource.h"
  9. #define CharSize 2 //for unicode file format
  10. typedef struct {
  11. DWORD root;
  12. DWORD position;
  13. } PHRINFO;
  14. int cvtphrase(char *FileName,char *OutName, char *idxName,DWORD *line)
  15. {
  16. FILE *fin;
  17. FILE *fout;
  18. FILE *fidx;
  19. BYTE buffer;
  20. WORD temp;
  21. PHRINFO code,oldcode;
  22. DWORD header[4];
  23. BOOL SortFlag=TRUE;
  24. int i;
  25. *line =1;
  26. header[0]=header[1]=header[2]=header[3]=0;
  27. // open input file
  28. if((fin = fopen(FileName,"rb")) ==NULL)
  29. return IDS_ERROPENFILE;
  30. fread(&temp,CharSize,1,fin); // for unicode prefix character
  31. // open output file
  32. if((fout=fopen(OutName,"wb"))==NULL)
  33. {
  34. fclose(fin);
  35. return IDS_ERRCREATEFILE;
  36. }
  37. // open index file
  38. if((fidx=fopen(idxName,"wb"))==NULL)
  39. {
  40. fclose(fin);
  41. fclose(fout);
  42. return IDS_ERRCREATEIDX;
  43. }
  44. code.position=0;
  45. oldcode.root=0;
  46. //fwrite(&code.position,4,sizeof(DWORD),fidx);
  47. fseek(fidx,16L,0); //header
  48. while(fread(&temp,1,CharSize,fin))
  49. {
  50. code.root=0;
  51. if (temp!=' ' && temp!=10 && temp!=13 && temp!='|') //�C�C�Ĥ@�r���ťզr��(�ΪťզC)�ɡA�ӦC�Y�����ѦC
  52. {
  53. // get roots
  54. i=0; // how many roots
  55. do {
  56. if(temp==' ') break;
  57. if (temp>255) //error format
  58. {
  59. fclose(fin);
  60. fclose(fout);
  61. fclose(fidx);
  62. return IDS_ERRFORMATROOT;
  63. }
  64. buffer=(BYTE)temp;
  65. if(buffer>='a' && buffer<='z') buffer-=('a'-'A'); // upcase
  66. // �N�r���ର�s�X
  67. if(buffer>='A' && buffer<='Z')
  68. buffer=buffer-'A'+5;
  69. else
  70. switch(buffer)
  71. {
  72. case ',': buffer=1; break;
  73. case '.': buffer=2; break;
  74. case '/': buffer=3; break;
  75. case ';': buffer=4; break;
  76. default:
  77. fclose(fin);
  78. fclose(fout);
  79. fclose(fidx);
  80. return IDS_ERRFORMATROOT;
  81. }
  82. code.root <<= 5;
  83. code.root |= (DWORD)buffer;
  84. i++;
  85. } while (fread(&temp,1,CharSize,fin));
  86. if (i>=5 || code.root==0) // to many roots!
  87. {
  88. fclose(fin);
  89. fclose(fout);
  90. fclose(fidx);
  91. return IDS_ERRFORMATROOTS;
  92. }
  93. else
  94. {
  95. code.root <<= (5-i)*5;
  96. if(SortFlag)
  97. {
  98. if(code.root<oldcode.root)
  99. {
  100. fclose(fin);
  101. fclose(fout);
  102. fclose(fidx);
  103. return IDS_ERRFORMATPHRASE;
  104. }
  105. oldcode.root=code.root;
  106. }
  107. }
  108. // cut space char
  109. while(fread(&temp,1,CharSize,fin))
  110. if(temp!=' ') break;
  111. if(feof(fin))
  112. {
  113. fclose(fin);
  114. fclose(fout);
  115. return IDS_ERRFORMATCODE;
  116. }
  117. // ���X�r��
  118. i=0;
  119. do {
  120. if(temp<=13)
  121. break;
  122. fwrite (&temp,1,sizeof(temp),fout); // write to output file
  123. i++;
  124. } while (fread(&temp,1,CharSize,fin));
  125. if (!i)
  126. {
  127. fclose(fin);
  128. fclose(fout);
  129. return IDS_ERRFORMATCODE;
  130. }
  131. fwrite (&code,1,sizeof(code),fidx); // write to index file
  132. code.position+=i;
  133. }
  134. if (SortFlag && temp=='|') // data not sort
  135. {
  136. header[0]=*line+1;
  137. code.root=0xffffffff;
  138. fwrite (&code,1,sizeof(code),fidx); // write to index file
  139. SortFlag = FALSE;
  140. }
  141. while(temp!=0x000a) // goto end of line ...
  142. if(!fread(&temp,1,CharSize,fin))
  143. break;
  144. (*line) ++;
  145. }
  146. header[1]=*line+1;
  147. code.root=0xffffffff;
  148. fwrite (&code,1,sizeof(code),fidx); // write to index file
  149. fseek(fidx,0L,0);
  150. fwrite (header,1,16,fidx); // write header
  151. fclose(fin);
  152. fclose(fout);
  153. fclose(fidx);
  154. return 0;
  155. }