fpmtools.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. { Find grep.exe }
  145. GrepExe:=GrepExeName;
  146. If not LocateExeFile(GrepExe) then
  147. Begin
  148. ErrorBox('Grep program not found',nil);
  149. Exit;
  150. End;
  151. { Try to load the word from the editor }
  152. If not(DeskTop^.First=nil) and
  153. (DeskTop^.First^.HelpCtx=hcSourceWindow) then
  154. Searchword:=PSourceWindow(DeskTop^.First)^.Editor^.GetCurrentWord
  155. else
  156. Searchword:='';
  157. { Don't use the listseparator in the file list else it's seen as 1 file
  158. (at least under linux }
  159. s:=highlightexts;
  160. ReplaceStr(s,';',' ');
  161. { add "" for args with spaces }
  162. { WARNING : text must still be entered in usual grep syntax }
  163. { -n is always added later because otherwise
  164. we don't get the line info PM }
  165. GrepArgs:=' -i "$TEXT" '+s;
  166. { Dialog }
  167. R.Assign(0,0,50,8);
  168. new(PGrepDialog,Init(R,'Grep arguments'));
  169. with PGrepDialog^ do
  170. begin
  171. R2.A.Y:=R.A.Y+3;
  172. R2.B.Y:=R2.A.Y+1;
  173. R2.A.X:=R.A.X+3;
  174. R2.B.X:=R.B.X-6;
  175. New(IL1, Init(R2, 128));
  176. IL1^.Data^:=SearchWord;
  177. Insert(IL1);
  178. R2.Move(0,-1);
  179. Insert(New(PLabel, Init(R2, '~T~ext to find', IL1)));
  180. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  181. Control := New(PHistory, Init(R1, IL1, TextGrepId));
  182. Insert(Control);
  183. R2.Move(0,4);
  184. New(IL2, Init(R2, 128));
  185. IL2^.Data^:=GrepArgs;
  186. Insert(IL2);
  187. R2.Move(0,-1);
  188. Insert(New(PLabel, Init(R2, '~G~rep arguments', IL2)));
  189. end;
  190. InsertButtons(PGrepDialog);
  191. IL1^.Select;
  192. if Desktop^.ExecView(PGrepDialog)=cmOK then
  193. begin
  194. SearchWord:=IL1^.Data^;
  195. if SearchWord<>'' then
  196. begin
  197. GrepArgs:=IL2^.Data^;
  198. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  199. { Linux ? }
  200. AddToolCommand(GrepExe+' -n '+GrepArgs);
  201. ToFocus:=ToolMessages^.count-1;
  202. if not ExecuteRedir(GrepExe,'-n '+GrepArgs,'',GrepOutName,GrepErrName) then
  203. Begin
  204. { 2 as exit code just means that
  205. some file vwere not found ! }
  206. if (IOStatus<>0) or (ExecuteResult<>2) then
  207. begin
  208. Params[0]:=IOStatus;
  209. Params[1]:=ExecuteResult;
  210. WarningBox(#3'Error running Grep'#13#3'DosError = %d'#13#3'Exit code = %d',@Params);
  211. end;
  212. End;
  213. {$I-}
  214. showmsg:=true;
  215. Assign(GrepOut,GrepOutName);
  216. Reset(GrepOut);
  217. error_in_reading:=false;
  218. GrepOutputLine:=0;
  219. While not eof(GrepOut) do
  220. begin
  221. readln(GrepOut,Line);
  222. Inc(GrepOutputLine);
  223. p:=pos(':',line);
  224. if p>0 then
  225. begin
  226. ModuleName:=copy(Line,1,p-1);
  227. Line:=Copy(Line,p+1,255);
  228. p:=pos(':',Line);
  229. val(copy(Line,1,p-1),lineNb,error);
  230. if error=0 then
  231. AddToolMessage(ModuleName,Copy(Line,p+1,255),LineNb,1)
  232. else
  233. error_in_reading:=true;
  234. end;
  235. end;
  236. Close(GrepOut);
  237. if not error_in_reading then
  238. Erase(GrepOut)
  239. else
  240. begin
  241. Params[0]:=GrepOutputLine;
  242. WarningBox(#3'Error reading Grep output'#13#3'In line %d of '+GrepOutName,@Params);
  243. end;
  244. { Delete also grep$$.err }
  245. if not error_in_reading then
  246. begin
  247. Assign(GrepOut,GrepErrName);
  248. Erase(GrepOut);
  249. end;
  250. {$I+}
  251. EatIO;
  252. end;
  253. end;
  254. Dispose(PGrepDialog, Done);
  255. UpdateToolMessages;
  256. if (ToFocus<>-1) then
  257. if Assigned(MessagesWindow) then
  258. MessagesWindow^.FocusItem(ToFocus);
  259. if showmsg then
  260. Messages;
  261. end;
  262. {
  263. $Log$
  264. Revision 1.15 1999-10-08 15:25:25 pierre
  265. + Grep read check added
  266. Revision 1.14 1999/09/22 16:17:31 pierre
  267. + HistList for Grep
  268. Revision 1.13 1999/08/03 20:22:35 peter
  269. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  270. + Desktop saving should work now
  271. - History saved
  272. - Clipboard content saved
  273. - Desktop saved
  274. - Symbol info saved
  275. * syntax-highlight bug fixed, which compared special keywords case sensitive
  276. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  277. * with 'whole words only' set, the editor didn't found occourences of the
  278. searched text, if the text appeared previously in the same line, but didn't
  279. satisfied the 'whole-word' condition
  280. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  281. (ie. the beginning of the selection)
  282. * when started typing in a new line, but not at the start (X=0) of it,
  283. the editor inserted the text one character more to left as it should...
  284. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  285. * Shift shouldn't cause so much trouble in TCodeEditor now...
  286. * Syntax highlight had problems recognizing a special symbol if it was
  287. prefixed by another symbol character in the source text
  288. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  289. Revision 1.12 1999/07/12 13:14:20 pierre
  290. * LineEnd bug corrected, now goes end of text even if selected
  291. + Until Return for debugger
  292. + Code for Quit inside GDB Window
  293. Revision 1.11 1999/03/02 13:48:30 peter
  294. * fixed far problem is fpdebug
  295. * tile/cascading with message window
  296. * grep fixes
  297. Revision 1.10 1999/02/22 12:46:57 peter
  298. * small fixes for linux and grep
  299. Revision 1.9 1999/02/22 11:29:37 pierre
  300. + added col info in MessageItem
  301. + grep uses HighLightExts and should work for linux
  302. Revision 1.8 1999/02/22 02:15:17 peter
  303. + default extension for save in the editor
  304. + Separate Text to Find for the grep dialog
  305. * fixed redir crash with tp7
  306. Revision 1.7 1999/02/20 15:18:31 peter
  307. + ctrl-c capture with confirm dialog
  308. + ascii table in the tools menu
  309. + heapviewer
  310. * empty file fixed
  311. * fixed callback routines in fpdebug to have far for tp7
  312. Revision 1.6 1999/02/05 13:51:42 peter
  313. * unit name of FPSwitches -> FPSwitch which is easier to use
  314. * some fixes for tp7 compiling
  315. Revision 1.5 1999/02/05 12:11:59 pierre
  316. + SourceDir that stores directories for sources that the
  317. compiler should not know about
  318. Automatically asked for addition when a new file that
  319. needed filedialog to be found is in an unknown directory
  320. Stored and retrieved from INIFile
  321. + Breakpoints conditions added to INIFile
  322. * Breakpoints insterted and removed at debin and end of debug session
  323. Revision 1.4 1999/02/04 15:59:08 pierre
  324. * grep$$$.out was not closed
  325. Revision 1.3 1999/02/04 13:32:09 pierre
  326. * Several things added (I cannot commit them independently !)
  327. + added TBreakpoint and TBreakpointCollection
  328. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  329. + Breakpoint list in INIFile
  330. * Select items now also depend of SwitchMode
  331. * Reading of option '-g' was not possible !
  332. + added search for -Fu args pathes in TryToOpen
  333. + added code for automatic opening of FileDialog
  334. if source not found
  335. Revision 1.2 1999/01/21 11:54:21 peter
  336. + tools menu
  337. + speedsearch in symbolbrowser
  338. * working run command
  339. Revision 1.1 1998/12/22 14:27:54 peter
  340. * moved
  341. Revision 1.2 1998/12/22 10:39:49 peter
  342. + options are now written/read
  343. + find and replace routines
  344. }