uBatch.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2004 Fréderic Bour
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. }
  16. unit uBatch;
  17. interface
  18. uses
  19. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  20. Dialogs, StdCtrls, FileCtrl, uEditor, uHSFParser, MasterUnit;
  21. const
  22. BrowseCaption = 'Select Directory';
  23. type
  24. TBatchEdit = class(TForm)
  25. WorkDirLbl: TLabel;
  26. WorkDirEdit: TEdit;
  27. WorkDirBtn: TButton;
  28. HsfDirLbl: TLabel;
  29. HsfDirEdit: TEdit;
  30. HsfDirBtn: TButton;
  31. GoBtn: TButton;
  32. LogMemo: TMemo;
  33. EnumCheck: TCheckBox;
  34. procedure GoBtnClick(Sender: TObject);
  35. procedure WorkDirBtnClick(Sender: TObject);
  36. procedure HsfDirBtnClick(Sender: TObject);
  37. procedure FormCreate(Sender: TObject);
  38. private
  39. { Déclarations privées }
  40. public
  41. { Déclarations publiques }
  42. Editor: TCEditorForm;
  43. end;
  44. var
  45. BatchEdit: TBatchEdit;
  46. implementation
  47. {$R *.dfm}
  48. procedure TBatchEdit.GoBtnClick(Sender: TObject);
  49. procedure Log(const S: string);
  50. begin
  51. LogMemo.Lines.Add(S);
  52. end;
  53. const
  54. Valids = faAnyFile and not (faDirectory or faSysFile or faHidden);
  55. var
  56. Sr: TSearchRec;
  57. Path, HSFs: string;
  58. F: TFileStream;
  59. begin
  60. DoEnum := EnumCheck.Checked;
  61. LogMemo.Clear;
  62. if Editor = nil then
  63. Exit;
  64. Path := IncludeTrailingPathDelimiter(WorkDirEdit.Text);
  65. HSFs := IncludeTrailingPathDelimiter(HsfDirEdit.Text);
  66. Log('Start processing...');
  67. if FindFirst(Path + '*.h', Valids, Sr) = 0 then
  68. begin
  69. repeat
  70. Log('Found: ' + Sr.Name);
  71. Editor.Clear;
  72. if Editor.ParseH(Path + Sr.Name) then
  73. begin
  74. Log('Processing ' + Sr.Name + ' ...');
  75. if DirectoryExists(HSFs + Sr.Name) then
  76. begin
  77. ClearCompletion(Editor.Lst);
  78. ImportDir(HSFs + Sr.Name, Editor, Editor.GetLine);
  79. Log('Found HSF Files ...');
  80. end;
  81. try
  82. F := TFileStream.Create(Path + ChangeFileExt(Sr.Name, '.ccf'), fmCreate);
  83. try
  84. Editor.SaveToStream(F);
  85. finally
  86. F.Free;
  87. end;
  88. except
  89. Log('Error while saving ccf for ' + Sr.Name);
  90. end;
  91. end;
  92. Editor.Modified := False;
  93. Log('');
  94. until FindNext(Sr) <> 0;
  95. FindClose(Sr);
  96. end;
  97. Editor.Modified := False;
  98. Log('Finished!');
  99. DoEnum := True;
  100. end;
  101. procedure TBatchEdit.WorkDirBtnClick(Sender: TObject);
  102. var
  103. Dir: string;
  104. begin
  105. Dir := WorkDirEdit.Text;
  106. if SelectDirectory(BrowseCaption, '', Dir) then
  107. WorkDirEdit.Text := Dir;
  108. end;
  109. procedure TBatchEdit.HsfDirBtnClick(Sender: TObject);
  110. var
  111. Dir: string;
  112. begin
  113. Dir := HsfDirEdit.Text;
  114. if SelectDirectory(BrowseCaption, '', Dir) then
  115. HsfDirEdit.Text := Dir;
  116. end;
  117. procedure TBatchEdit.FormCreate(Sender: TObject);
  118. var
  119. Folder: string;
  120. begin
  121. Folder := IncludeTrailingPathDelimiter(TIGCCFolder);
  122. WorkDirEdit.Text := Folder + CIncludeLocation;
  123. Folder := Folder + 'Src\doc\System\Include';
  124. if DirectoryExists(Folder) then
  125. HsfDirEdit.Text := Folder
  126. else
  127. HsfDirEdit.Text := TIGCCFolder;
  128. end;
  129. end.