fpmtools.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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.Messages;
  13. begin
  14. if MessagesWindow=nil then
  15. Desktop^.Insert(New(PMessagesWindow, Init))
  16. else
  17. MessagesWindow^.Focus;
  18. end;
  19. procedure TIDEApp.DoAsciiTable;
  20. begin
  21. if ASCIIChart=nil then
  22. begin
  23. New(ASCIIChart, Init);
  24. Desktop^.Insert(ASCIIChart);
  25. end
  26. else
  27. ASCIIChart^.Focus;
  28. end;
  29. procedure TIDEApp.Calculator;
  30. begin
  31. with CalcWindow^ do
  32. begin
  33. if GetState(sfVisible)=false then Show;
  34. MakeFirst;
  35. end;
  36. end;
  37. procedure TIDEApp.ExecuteTool(Idx: integer);
  38. var Title,ProgramPath,Params: string;
  39. W: PSourceWindow;
  40. ToFocus : sw_integer;
  41. Wo: word;
  42. Err: integer;
  43. CaptureFile: string;
  44. ExecMode: TExecType;
  45. Executed: boolean;
  46. begin
  47. if (Idx<1) or (Idx>GetToolCount) then Exit;
  48. GetToolParams(Idx-1,Title,ProgramPath,Params,Wo);
  49. Err:=ParseToolParams(Params,false);
  50. if Err=-1 then Exit;
  51. if Err<>0 then
  52. begin ErrorBox(^C'Error parsing tool params.',nil); Exit; end;
  53. if CaptureToolTo<>capNone then
  54. begin
  55. CaptureFile:=ToolCaptureName;
  56. ExecMode:=exNoSwap;
  57. end
  58. else
  59. begin
  60. CaptureFile:='';
  61. ExecMode:=exNormal;
  62. end;
  63. EraseFile(CaptureFile);
  64. EraseFile(FilterCaptureName);
  65. if CaptureToolTo=capMessageWindow then
  66. begin
  67. AddToolCommand(ProgramPath+' '+Params);
  68. ToFocus:=ToolMessages^.count-1;
  69. end
  70. else
  71. ToFocus:=-1;
  72. if CaptureToolTo<>capNone then
  73. ShowMessage('Executing tool '+KillTilde(Title)+'...');
  74. Executed:=DoExecute(ProgramPath,Params,'',CaptureFile,ExecMode);
  75. if CaptureToolTo<>capNone then
  76. HideMessage;
  77. if Executed then
  78. if (DosError=0) and (DosExitCode=0) then
  79. begin
  80. if CaptureToolTo=capEditWindow then
  81. begin
  82. W:=OpenEditorWindow(nil,'',0,0);
  83. if W<>nil then
  84. if StartEditor(W^.Editor,CaptureFile)=false then
  85. ErrorBox('Error reading output.',nil);
  86. end
  87. else
  88. if ToolFilter<>'' then
  89. begin
  90. ShowMessage('Executing filter for '+KillTilde(Title)+'...');
  91. DoExecute(ToolFilter,'',CaptureFile,FilterCaptureName,exNoSwap);
  92. HideMessage;
  93. if (DosError=0) and (DosExitCode=0) then
  94. begin
  95. if ExistsFile(FilterCaptureName)=false then
  96. ErrorBox('Can''t find filtered output.',nil)
  97. else
  98. if ProcessMessageFile(FilterCaptureName)=false then
  99. ErrorBox('Error processing filtered output.',nil);
  100. end
  101. else
  102. if (DosError<>0) then
  103. ErrorBox('Error executing filter '+KillTilde(GetToolName(Idx-1)),nil) else
  104. if DosExitCode<>0 then
  105. ErrorBox('Filter execution successful. Exit code '+IntToStr(DosExitCode),nil);
  106. UpdateToolMessages;
  107. if (ToFocus<>-1) then
  108. if Assigned(MessagesWindow) then
  109. MessagesWindow^.FocusItem(ToFocus);
  110. if DosError=0 then
  111. Messages;
  112. end;
  113. end else
  114. if (DosError<>0) then
  115. ErrorBox('Error executing tool '+KillTilde(GetToolName(Idx-1)),nil) else
  116. if DosExitCode<>0 then
  117. ErrorBox('Tool execution successful. Exit code '+IntToStr(DosExitCode),nil);
  118. {$ifndef DEBUG}
  119. EraseFile(CaptureFile);
  120. EraseFile(FilterCaptureName);
  121. {$endif}
  122. end;
  123. procedure TIDEApp.DoGrep;
  124. Const
  125. GrepOutName = 'grep$$.out';
  126. GrepErrName = 'grep$$.err';
  127. GrepExeName = 'grep'+ExeExt;
  128. var
  129. PGrepDialog : PCenterDialog;
  130. R,R1,R2 : TRect;
  131. Control : PView;
  132. IL1,IL2 : PInputLine;
  133. s : string;
  134. p,lineNb,GrepOutputLine : longint;
  135. error : word;
  136. showmsg,error_in_reading : boolean;
  137. ToFocus : sw_integer;
  138. searchword,
  139. GrepExe,GrepArgs,Line,ModuleName : String;
  140. GrepOut : text;
  141. Params : Array[0..4] of longint;
  142. begin
  143. showmsg:=false;
  144. ToFocus:=-1;
  145. { Find grep.exe }
  146. GrepExe:=GrepExeName;
  147. If not LocateExeFile(GrepExe) then
  148. Begin
  149. ErrorBox('Grep program not found',nil);
  150. Exit;
  151. End;
  152. { Try to load the word from the editor }
  153. If not(DeskTop^.Current=nil) and
  154. (DeskTop^.Current^.HelpCtx=hcSourceWindow) then
  155. Searchword:=PSourceWindow(DeskTop^.Current)^.Editor^.GetCurrentWord
  156. else
  157. Searchword:='';
  158. { Don't use the listseparator in the file list else it's seen as 1 file
  159. (at least under linux }
  160. s:=highlightexts;
  161. ReplaceStr(s,';',' ');
  162. { add "" for args with spaces }
  163. { WARNING : text must still be entered in usual grep syntax }
  164. { -n is always added later because otherwise
  165. we don't get the line info PM }
  166. GrepArgs:=' -i "$TEXT" '+s;
  167. { Dialog }
  168. R.Assign(0,0,50,8);
  169. new(PGrepDialog,Init(R,'Grep arguments'));
  170. with PGrepDialog^ do
  171. begin
  172. R2.A.Y:=R.A.Y+3;
  173. R2.B.Y:=R2.A.Y+1;
  174. R2.A.X:=R.A.X+3;
  175. R2.B.X:=R.B.X-6;
  176. New(IL1, Init(R2, 128));
  177. IL1^.Data^:=SearchWord;
  178. Insert(IL1);
  179. R2.Move(0,-1);
  180. Insert(New(PLabel, Init(R2, '~T~ext to find', IL1)));
  181. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  182. Control := New(PHistory, Init(R1, IL1, TextGrepId));
  183. Insert(Control);
  184. R2.Move(0,4);
  185. New(IL2, Init(R2, 128));
  186. IL2^.Data^:=GrepArgs;
  187. Insert(IL2);
  188. R2.Move(0,-1);
  189. Insert(New(PLabel, Init(R2, '~G~rep arguments', IL2)));
  190. end;
  191. InsertButtons(PGrepDialog);
  192. IL1^.Select;
  193. if Desktop^.ExecView(PGrepDialog)=cmOK then
  194. begin
  195. SearchWord:=IL1^.Data^;
  196. if SearchWord<>'' then
  197. begin
  198. GrepArgs:=IL2^.Data^;
  199. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  200. { Linux ? }
  201. AddToolCommand(GrepExe+' -n '+GrepArgs);
  202. ToFocus:=ToolMessages^.count-1;
  203. if not ExecuteRedir(GrepExe,'-n '+GrepArgs,'',GrepOutName,GrepErrName) then
  204. Begin
  205. { 2 as exit code just means that
  206. some file vwere not found ! }
  207. if (IOStatus<>0) or (ExecuteResult<>2) then
  208. begin
  209. Params[0]:=IOStatus;
  210. Params[1]:=ExecuteResult;
  211. WarningBox(#3'Error running Grep'#13#3'DosError = %d'#13#3'Exit code = %d',@Params);
  212. end;
  213. End;
  214. {$I-}
  215. showmsg:=true;
  216. Assign(GrepOut,GrepOutName);
  217. Reset(GrepOut);
  218. error_in_reading:=false;
  219. GrepOutputLine:=0;
  220. While not eof(GrepOut) do
  221. begin
  222. readln(GrepOut,Line);
  223. Inc(GrepOutputLine);
  224. p:=pos(':',line);
  225. if p>0 then
  226. begin
  227. ModuleName:=copy(Line,1,p-1);
  228. Line:=Copy(Line,p+1,255);
  229. p:=pos(':',Line);
  230. val(copy(Line,1,p-1),lineNb,error);
  231. if error=0 then
  232. AddToolMessage(ModuleName,Copy(Line,p+1,255),LineNb,1)
  233. else
  234. error_in_reading:=true;
  235. end;
  236. end;
  237. Close(GrepOut);
  238. if not error_in_reading then
  239. Erase(GrepOut)
  240. else
  241. begin
  242. Params[0]:=GrepOutputLine;
  243. WarningBox(#3'Error reading Grep output'#13#3'In line %d of '+GrepOutName,@Params);
  244. end;
  245. { Delete also grep$$.err }
  246. if not error_in_reading then
  247. begin
  248. Assign(GrepOut,GrepErrName);
  249. Erase(GrepOut);
  250. end;
  251. {$I+}
  252. EatIO;
  253. end;
  254. end;
  255. Dispose(PGrepDialog, Done);
  256. UpdateToolMessages;
  257. if (ToFocus<>-1) then
  258. if Assigned(MessagesWindow) then
  259. MessagesWindow^.FocusItem(ToFocus);
  260. if showmsg then
  261. Messages;
  262. end;
  263. {
  264. $Log$
  265. Revision 1.17 2000-02-10 00:48:02 pierre
  266. * avoid crash for empty string
  267. Revision 1.16 2000/02/02 22:49:44 pierre
  268. * use desktop^.current for current word in grep
  269. Revision 1.15 1999/10/08 15:25:25 pierre
  270. + Grep read check added
  271. Revision 1.14 1999/09/22 16:17:31 pierre
  272. + HistList for Grep
  273. Revision 1.13 1999/08/03 20:22:35 peter
  274. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  275. + Desktop saving should work now
  276. - History saved
  277. - Clipboard content saved
  278. - Desktop saved
  279. - Symbol info saved
  280. * syntax-highlight bug fixed, which compared special keywords case sensitive
  281. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  282. * with 'whole words only' set, the editor didn't found occourences of the
  283. searched text, if the text appeared previously in the same line, but didn't
  284. satisfied the 'whole-word' condition
  285. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  286. (ie. the beginning of the selection)
  287. * when started typing in a new line, but not at the start (X=0) of it,
  288. the editor inserted the text one character more to left as it should...
  289. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  290. * Shift shouldn't cause so much trouble in TCodeEditor now...
  291. * Syntax highlight had problems recognizing a special symbol if it was
  292. prefixed by another symbol character in the source text
  293. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  294. Revision 1.12 1999/07/12 13:14:20 pierre
  295. * LineEnd bug corrected, now goes end of text even if selected
  296. + Until Return for debugger
  297. + Code for Quit inside GDB Window
  298. Revision 1.11 1999/03/02 13:48:30 peter
  299. * fixed far problem is fpdebug
  300. * tile/cascading with message window
  301. * grep fixes
  302. Revision 1.10 1999/02/22 12:46:57 peter
  303. * small fixes for linux and grep
  304. Revision 1.9 1999/02/22 11:29:37 pierre
  305. + added col info in MessageItem
  306. + grep uses HighLightExts and should work for linux
  307. Revision 1.8 1999/02/22 02:15:17 peter
  308. + default extension for save in the editor
  309. + Separate Text to Find for the grep dialog
  310. * fixed redir crash with tp7
  311. Revision 1.7 1999/02/20 15:18:31 peter
  312. + ctrl-c capture with confirm dialog
  313. + ascii table in the tools menu
  314. + heapviewer
  315. * empty file fixed
  316. * fixed callback routines in fpdebug to have far for tp7
  317. Revision 1.6 1999/02/05 13:51:42 peter
  318. * unit name of FPSwitches -> FPSwitch which is easier to use
  319. * some fixes for tp7 compiling
  320. Revision 1.5 1999/02/05 12:11:59 pierre
  321. + SourceDir that stores directories for sources that the
  322. compiler should not know about
  323. Automatically asked for addition when a new file that
  324. needed filedialog to be found is in an unknown directory
  325. Stored and retrieved from INIFile
  326. + Breakpoints conditions added to INIFile
  327. * Breakpoints insterted and removed at debin and end of debug session
  328. Revision 1.4 1999/02/04 15:59:08 pierre
  329. * grep$$$.out was not closed
  330. Revision 1.3 1999/02/04 13:32:09 pierre
  331. * Several things added (I cannot commit them independently !)
  332. + added TBreakpoint and TBreakpointCollection
  333. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  334. + Breakpoint list in INIFile
  335. * Select items now also depend of SwitchMode
  336. * Reading of option '-g' was not possible !
  337. + added search for -Fu args pathes in TryToOpen
  338. + added code for automatic opening of FileDialog
  339. if source not found
  340. Revision 1.2 1999/01/21 11:54:21 peter
  341. + tools menu
  342. + speedsearch in symbolbrowser
  343. * working run command
  344. Revision 1.1 1998/12/22 14:27:54 peter
  345. * moved
  346. Revision 1.2 1998/12/22 10:39:49 peter
  347. + options are now written/read
  348. + find and replace routines
  349. }