fpmtools.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Tools menu entries
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  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.
  11. **********************************************************************}
  12. procedure TIDEApp.DoAsciiTable;
  13. var
  14. P: PAsciiChart;
  15. begin
  16. P := New(PAsciiChart, Init);
  17. P^.HelpCtx := hcAsciiTable;
  18. InsertWindow(P);
  19. end;
  20. procedure TIDEApp.Calculator;
  21. begin
  22. with CalcWindow^ do
  23. begin
  24. if GetState(sfVisible)=false then Show;
  25. MakeFirst;
  26. end;
  27. end;
  28. procedure TIDEApp.ExecuteTool(Idx: integer);
  29. var Title,ProgramPath,Params: string;
  30. W: word;
  31. Err: integer;
  32. begin
  33. if (Idx<1) or (Idx>GetToolCount) then Exit;
  34. GetToolParams(Idx-1,Title,ProgramPath,Params,W);
  35. Err:=ParseToolParams(Params,false);
  36. if Err=-1 then Exit;
  37. if Err<>0 then
  38. begin ErrorBox(^C'Error parsing tool params.',nil); Exit; end;
  39. DoExecute(ProgramPath,Params,false);
  40. if (DosError<>0) then
  41. ErrorBox('Error executing tool '+KillTilde(GetToolName(Idx-1)),nil) else
  42. if DosExitCode<>0 then
  43. ErrorBox('Execution successful. Exit code '+IntToStr(DosExitCode),nil);
  44. end;
  45. procedure TIDEApp.Grep;
  46. Const
  47. GrepOutName = 'grep$$.out';
  48. GrepErrName = 'grep$$.err';
  49. GrepExeName = 'grep'+ExeExt;
  50. var
  51. PGrepDialog : PCenterDialog;
  52. R,R2 : TRect;
  53. IL1,IL2 : PInputLine;
  54. s : string;
  55. p,lineNb : longint;
  56. error : word;
  57. searchword,
  58. GrepExe,GrepArgs,Line,ModuleName : String;
  59. GrepOut : text;
  60. Params : Array[0..4] of longint;
  61. begin
  62. { Find grep.exe }
  63. GrepExe:=GrepExeName;
  64. If not LocateExeFile(GrepExe) then
  65. Begin
  66. ErrorBox('Grep program not found',nil);
  67. Exit;
  68. End;
  69. { Try to load the word from the editor }
  70. If not(DeskTop^.First=nil) and
  71. (DeskTop^.First^.HelpCtx=hcSourceWindow) then
  72. Searchword:=PSourceWindow(DeskTop^.First)^.Editor^.GetCurrentWord
  73. else
  74. Searchword:='';
  75. { Don't use the listseparator in the file list else it's seen as 1 file
  76. (at least under linux }
  77. s:=highlightexts;
  78. ReplaceStr(s,';',' ');
  79. { add "" for args with spaces }
  80. { WARNING : text must still be entered in usual grep syntax }
  81. GrepArgs:='-n -i "$TEXT" '+s;
  82. { Dialog }
  83. R.Assign(0,0,45,8);
  84. new(PGrepDialog,Init(R,'Grep arguments'));
  85. with PGrepDialog^ do
  86. begin
  87. R2.A.Y:=R.A.Y+3;
  88. R2.B.Y:=R2.A.Y+1;
  89. R2.A.X:=R.A.X+3;
  90. R2.B.X:=R.B.X-3;
  91. New(IL1, Init(R2, 128));
  92. IL1^.Data^:=SearchWord;
  93. Insert(IL1);
  94. R2.Move(0,-1);
  95. Insert(New(PLabel, Init(R2, '~T~ext to find', IL1)));
  96. R2.Move(0,4);
  97. New(IL2, Init(R2, 128));
  98. IL2^.Data^:=GrepArgs;
  99. Insert(IL2);
  100. R2.Move(0,-1);
  101. Insert(New(PLabel, Init(R2, '~G~rep arguments', IL2)));
  102. end;
  103. InsertButtons(PGrepDialog);
  104. IL1^.Select;
  105. if Desktop^.ExecView(PGrepDialog)=cmOK then
  106. begin
  107. SearchWord:=IL1^.Data^;
  108. if SearchWord<>'' then
  109. begin
  110. GrepArgs:=IL2^.Data^;
  111. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  112. { Linux ? }
  113. if not ExecuteRedir(GrepExe,GrepArgs,GrepOutName,GrepErrName) then
  114. Begin
  115. { 2 as exit code just means that
  116. some file vwere not found ! }
  117. if (IOStatus<>0) or (ExecuteResult<>2) then
  118. begin
  119. Params[0]:=IOStatus;
  120. Params[1]:=ExecuteResult;
  121. WarningBox(#3'Error running Grep'#13#3'DosError = %d'#13#3'Exit code = %d',@Params);
  122. end;
  123. End;
  124. {$I-}
  125. Assign(GrepOut,GrepOutName);
  126. Reset(GrepOut);
  127. While not eof(GrepOut) do
  128. begin
  129. readln(GrepOut,Line);
  130. p:=pos(':',line);
  131. if p>0 then
  132. begin
  133. ModuleName:=copy(Line,1,p-1);
  134. Line:=Copy(Line,p+1,255);
  135. p:=pos(':',Line);
  136. val(copy(Line,1,p-1),lineNb,error);
  137. if error=0 then
  138. ProgramInfoWindow^.AddMessage(V_Normal,Copy(Line,p+1,255),
  139. ModuleName,LineNb,1);
  140. end;
  141. ProgramInfoWindow^.Show;
  142. ProgramInfoWindow^.MakeFirst;
  143. end;
  144. Close(GrepOut);
  145. Erase(GrepOut);
  146. { Delete also grep$$.err }
  147. Assign(GrepOut,GrepErrName);
  148. Erase(GrepOut);
  149. {$I+}
  150. EatIO;
  151. end;
  152. end;
  153. Dispose(PGrepDialog, Done);
  154. end;
  155. {
  156. $Log$
  157. Revision 1.10 1999-02-22 12:46:57 peter
  158. * small fixes for linux and grep
  159. Revision 1.9 1999/02/22 11:29:37 pierre
  160. + added col info in MessageItem
  161. + grep uses HighLightExts and should work for linux
  162. Revision 1.8 1999/02/22 02:15:17 peter
  163. + default extension for save in the editor
  164. + Separate Text to Find for the grep dialog
  165. * fixed redir crash with tp7
  166. Revision 1.7 1999/02/20 15:18:31 peter
  167. + ctrl-c capture with confirm dialog
  168. + ascii table in the tools menu
  169. + heapviewer
  170. * empty file fixed
  171. * fixed callback routines in fpdebug to have far for tp7
  172. Revision 1.6 1999/02/05 13:51:42 peter
  173. * unit name of FPSwitches -> FPSwitch which is easier to use
  174. * some fixes for tp7 compiling
  175. Revision 1.5 1999/02/05 12:11:59 pierre
  176. + SourceDir that stores directories for sources that the
  177. compiler should not know about
  178. Automatically asked for addition when a new file that
  179. needed filedialog to be found is in an unknown directory
  180. Stored and retrieved from INIFile
  181. + Breakpoints conditions added to INIFile
  182. * Breakpoints insterted and removed at debin and end of debug session
  183. Revision 1.4 1999/02/04 15:59:08 pierre
  184. * grep$$$.out was not closed
  185. Revision 1.3 1999/02/04 13:32:09 pierre
  186. * Several things added (I cannot commit them independently !)
  187. + added TBreakpoint and TBreakpointCollection
  188. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  189. + Breakpoint list in INIFile
  190. * Select items now also depend of SwitchMode
  191. * Reading of option '-g' was not possible !
  192. + added search for -Fu args pathes in TryToOpen
  193. + added code for automatic opening of FileDialog
  194. if source not found
  195. Revision 1.2 1999/01/21 11:54:21 peter
  196. + tools menu
  197. + speedsearch in symbolbrowser
  198. * working run command
  199. Revision 1.1 1998/12/22 14:27:54 peter
  200. * moved
  201. Revision 1.2 1998/12/22 10:39:49 peter
  202. + options are now written/read
  203. + find and replace routines
  204. }