2
0

fpmtools.inc 13 KB

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