fpmtools.inc 13 KB

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