UIsxclassesParser.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. unit UIsxclassesParser;
  2. interface
  3. uses
  4. Classes;
  5. type
  6. TIsxclassesParser = class
  7. private
  8. FLines: TStringList;
  9. FTypes: TStringList;
  10. public
  11. constructor Create();
  12. destructor Destroy(); override;
  13. procedure Parse(const FileName: String);
  14. procedure SaveXML(const HeaderFileName, HeaderFileName2, FooterFileName, OutputFileName: String);
  15. end;
  16. implementation
  17. uses
  18. Windows,
  19. SysUtils;
  20. {$IFNDEF UNICODE}
  21. function CharInSet(C: AnsiChar; const CharSet: TSysCharSet): Boolean;
  22. begin
  23. Result := C in CharSet;
  24. end;
  25. {$ENDIF}
  26. constructor TIsxclassesParser.Create();
  27. begin
  28. inherited;
  29. FLines := TStringList.Create();
  30. FTypes := TStringList.Create();
  31. end;
  32. destructor TIsxclassesParser.Destroy();
  33. begin
  34. FTypes.Free();
  35. FLines.Free();
  36. inherited;
  37. end;
  38. procedure TIsxclassesParser.Parse(const FileName: String);
  39. var
  40. F: TextFile;
  41. S: String;
  42. P: Integer;
  43. begin
  44. AssignFile(F, FileName);
  45. Reset(F);
  46. try
  47. while not Eof(F) do begin
  48. ReadLn(F, S);
  49. FLines.Add(S);
  50. P := Pos('=', S);
  51. if P > 1 then
  52. FTypes.Add(Trim(Copy(S, 1, P-1)))
  53. end;
  54. finally
  55. CloseFile(F);
  56. end;
  57. end;
  58. procedure TIsxclassesParser.SaveXML(const HeaderFileName, HeaderFileName2, FooterFileName, OutputFileName: String);
  59. procedure FCopyFile(const SourceFileName, DestFileName: String; AppendToDestFile: Boolean);
  60. var
  61. F1, F2: TextFile;
  62. S: String;
  63. begin
  64. AssignFile(F1, SourceFileName);
  65. Reset(F1);
  66. try
  67. AssignFile(F2, DestFileName);
  68. if AppendToDestFile then begin
  69. if FileExists(DestFileName) then
  70. Append(F2)
  71. else
  72. Reset(F2);
  73. end else
  74. Rewrite(F2);
  75. try
  76. while not Eof(F1) do begin
  77. ReadLn(F1, S);
  78. WriteLn(F2, S);
  79. end;
  80. finally
  81. CloseFile(F2);
  82. end;
  83. finally
  84. CloseFile(F1);
  85. end;
  86. end;
  87. function FGetNextPart(var Text: PChar): String;
  88. var
  89. P: PChar;
  90. begin
  91. case Text^ of
  92. #0:
  93. begin
  94. Result := '';
  95. end;
  96. #1..#32:
  97. begin
  98. P := Text;
  99. Inc(Text);
  100. while CharInSet(Text^ , [#1..#32]) do
  101. Inc(Text);
  102. SetString(Result, P, Text - P);
  103. end;
  104. '(', ')', ',', '=', ':', ';', '[', ']':
  105. begin
  106. Result := Text^;
  107. Inc(Text);
  108. end;
  109. '0'..'9', 'A'..'Z', 'a'..'z', '_', '.':
  110. begin
  111. P := Text;
  112. Inc(Text);
  113. while CharInSet(Text^ , ['0'..'9', 'A'..'Z', 'a'..'z', '_', '.']) do
  114. Inc(Text);
  115. SetString(Result, P, Text - P);
  116. end;
  117. else
  118. raise Exception.CreateFmt('Invalid symbol ''%s'' found', [Text^]);
  119. end;
  120. end;
  121. function FLinkTypes(const S: String): String;
  122. var
  123. Text: PChar;
  124. NextPart: String;
  125. begin
  126. Result := '';
  127. Text := PChar(S);
  128. NextPart := FGetNextPart(Text);
  129. while NextPart <> '' do begin
  130. if FTypes.IndexOf(NextPart) >= 0 then begin
  131. if Result = '' then //start of line = object definition
  132. NextPart := '<a name="' + NextPart + '">' + NextPart + '</a>'
  133. else
  134. NextPart := '<anchorlink name="' + NextPart + '">' + NextPart + '</anchorlink>';
  135. end;
  136. Result := Result + NextPart;
  137. NextPart := FGetNextPart(Text);
  138. end;
  139. end;
  140. function FConvertLeadingSpacesToNbsp(const S: String): String;
  141. var
  142. I: Integer;
  143. begin
  144. Result := S;
  145. I := 1;
  146. while (I <= Length(Result)) and (Result[I] = ' ') do begin
  147. Delete(Result, I, 1);
  148. Insert('&nbsp;', Result, I);
  149. Inc(I, Length('&nbsp;'));
  150. end;
  151. end;
  152. var
  153. F: TextFile;
  154. I: Integer;
  155. S: String;
  156. begin
  157. FCopyFile(HeaderFileName, OutputFileName, False);
  158. AssignFile(F, OutputFileName);
  159. Append(F);
  160. try
  161. for I := 0 to FTypes.Count-1 do begin
  162. S := '<keyword value="' + FTypes[I] + '" anchor="' + FTypes[I] + '" />';
  163. WriteLn(F, S);
  164. end;
  165. WriteLn(F, '<keyword value="MainForm" />');
  166. WriteLn(F, '<keyword value="WizardForm" />');
  167. WriteLn(F, '<keyword value="UninstallProgressForm" />');
  168. finally
  169. CloseFile(F);
  170. end;
  171. FCopyFile(HeaderFileName2, OutputFileName, True);
  172. AssignFile(F, OutputFileName);
  173. Append(F);
  174. try
  175. WriteLn(F, '<p><br/><tt>');
  176. for I := 0 to FLines.Count-1 do begin
  177. S := FLinkTypes(FLines[I]);
  178. S := FConvertLeadingSpacesToNbsp(S);
  179. WriteLn(F, S, '<br/>');
  180. end;
  181. WriteLn(F, '</tt></p>');
  182. finally
  183. CloseFile(F);
  184. end;
  185. FCopyFile(FooterFileName, OutputFileName, True);
  186. end;
  187. end.