fpmtools.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. {MainUnit fpide.pas}
  2. {
  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. TextFile : Text;
  45. ExecMode: TExecType;
  46. Executed: boolean;
  47. begin
  48. if (Idx<1) or (Idx>GetToolCount) then Exit;
  49. InitToolProcessing;
  50. GetToolParams(Idx-1,Title,ProgramPath,Params,Wo);
  51. InitToolTempFiles;
  52. Err:=ParseToolParams(Params,false);
  53. if Err=-1 then
  54. begin
  55. DoneToolTempFiles;
  56. Exit;
  57. end;
  58. if Err<>0 then
  59. begin ErrorBox(msg_errorparsingtoolparams,nil); Exit; end;
  60. if CaptureToolTo<>capNone then
  61. begin
  62. if ToolOutput<>'' then
  63. begin
  64. CaptureFile:=ToolOutput;
  65. end
  66. else
  67. CaptureFile:=ToolCaptureName;
  68. ExecMode:=exNoSwap;
  69. end
  70. else
  71. begin
  72. CaptureFile:='';
  73. ExecMode:=exNormal;
  74. end;
  75. EraseFile(CaptureFile);
  76. EraseFile(FilterCaptureName);
  77. EraseFile(ToolCaptureErr);
  78. if CaptureToolTo=capMessageWindow then
  79. begin
  80. Messages;
  81. AddToolCommand(ProgramPath+' '+Params);
  82. UpdateToolMessages;
  83. ToFocus:=ToolMessages^.count-1;
  84. end
  85. else
  86. ToFocus:=-1;
  87. if CaptureToolTo<>capNone then
  88. ShowMessage(FormatStrStr(msg_executingtool,KillTilde(Title)));
  89. Executed:=DoExecute(ProgramPath,Params,'',CaptureFile,ToolCaptureErr,ExecMode);
  90. if CaptureToolTo<>capNone then
  91. HideMessage;
  92. if Executed then
  93. begin
  94. if (DosError=0) {and (DosExitCode=0)} then
  95. begin
  96. if CaptureToolTo=capEditWindow then
  97. begin
  98. if ToolOutput<>'' then
  99. W:=OpenEditorWindow(nil,ToolOutput,0,0)
  100. else
  101. begin
  102. W:=OpenEditorWindow(nil,'',0,0);
  103. if W<>nil then
  104. if StartEditor(W^.Editor,CaptureFile)=false then
  105. ErrorBox(msg_errorreadingoutput,nil);
  106. end;
  107. end
  108. else if (ToolFilter<>'') or (CaptureToolTo=capMessageWindow) then
  109. begin
  110. if ToolFilter<>'' then
  111. begin
  112. ShowMessage(FormatStrStr(msg_executingfilterfor,KillTilde(Title)));
  113. DoExecute(ToolFilter,'',CaptureFile,FilterCaptureName,'',exNoSwap);
  114. HideMessage;
  115. if (DosError=0) and (DosExitCode=0) then
  116. begin
  117. if ExistsFile(FilterCaptureName)=false then
  118. ErrorBox(msg_cantfindfilteredoutput,nil)
  119. else
  120. if ProcessMessageFile(FilterCaptureName)=false then
  121. ErrorBox(msg_errorprocessingfilteredoutput,nil);
  122. end;
  123. if (DosError<>0) then
  124. ErrorBox(FormatStrStr(msg_errorexecutingfilter,KillTilde(GetToolName(Idx-1))),nil) else
  125. if DosExitCode<>0 then
  126. ErrorBox(FormatStrInt(msg_filterexecutionsuccessfulexitcodeis,DosExitCode),nil);
  127. end
  128. else
  129. begin
  130. if ExistsFile(CaptureFile) then
  131. begin
  132. Assign(TextFile,CaptureFile);
  133. Reset(TextFile);
  134. while not eof(TextFile) do
  135. begin
  136. Readln(TextFile,Params);
  137. AddToolCommand(Params);
  138. end;
  139. Close(TextFile);
  140. UpdateToolMessages;
  141. if Assigned(MessagesWindow) then
  142. MessagesWindow^.MakeFirst;
  143. end;
  144. end;
  145. UpdateToolMessages;
  146. if (ToFocus<>-1) then
  147. if Assigned(MessagesWindow) then
  148. MessagesWindow^.FocusItem(ToFocus);
  149. if DosError=0 then
  150. Messages;
  151. end;
  152. end;
  153. end;
  154. if (DosError<>0) or (DosExitCode<>0) or (SizeOfFile(ToolCaptureErr)>0) then
  155. begin
  156. if (DosError<>0) then
  157. ErrorBox(FormatStrStr(msg_errorexecutingtool,KillTilde(GetToolName(Idx-1))),nil) else
  158. if DosExitCode<>0 then
  159. ErrorBox(FormatStrInt(msg_toolexecutionsuccessfulexitcodeis,DosExitCode),nil);
  160. {$i-}
  161. Assign(TextFile,ToolCaptureErr);
  162. Reset(TextFile);
  163. while not eof(TextFile) do
  164. begin
  165. Readln(TextFile,Params);
  166. AddToolCommand(Params);
  167. end;
  168. Close(TextFile);
  169. UpdateToolMessages;
  170. if Assigned(MessagesWindow) then
  171. begin
  172. MessagesWindow^.MakeFirst;
  173. if (ToFocus<>-1) then
  174. MessagesWindow^.FocusItem(ToFocus);
  175. end;
  176. end;
  177. {$ifndef DEBUG}
  178. if ToolOutput='' then
  179. begin
  180. EraseFile(CaptureFile);
  181. ToolOutput:='';
  182. end;
  183. EraseFile(FilterCaptureName);
  184. EraseFile(ToolCaptureErr);
  185. {$endif}
  186. { In case we have something that the compiler touched }
  187. AskToReloadAllModifiedFiles;
  188. DoneToolTempFiles;
  189. end;
  190. procedure TIDEApp.DoGrep;
  191. Const
  192. GrepExeName = 'grep'+ExeExt;
  193. var
  194. PGrepDialog : PCenterDialog;
  195. R,R1,R2 : TRect;
  196. Control : PView;
  197. IL1,IL2 : PEditorInputLine;
  198. s : string;
  199. p,lineNb,GrepOutputLine : longint;
  200. error : word;
  201. PosText : longint;
  202. showmsg,error_in_reading,FirstMsg : boolean;
  203. ToFocus : sw_integer;
  204. searchword,
  205. GrepExe,GrepArgs,Line,ModuleName : String;
  206. GrepOut : text;
  207. Params : Array[0..4] of longint;
  208. begin
  209. showmsg:=false;
  210. ToFocus:=-1;
  211. { Find grep.exe }
  212. GrepExe:=GrepExeName;
  213. If not LocateExeFile(GrepExe) then
  214. Begin
  215. ErrorBox(msg_grepprogramnotfound,nil);
  216. Exit;
  217. End;
  218. { Try to load the word from the editor }
  219. If not(DeskTop^.Current=nil) and
  220. (DeskTop^.Current^.HelpCtx=hcSourceWindow) then
  221. Searchword:=PSourceWindow(DeskTop^.Current)^.Editor^.GetCurrentWord
  222. else
  223. Searchword:='';
  224. { Don't use the listseparator in the file list else it's seen as 1 file
  225. (at least under linux }
  226. s:=highlightexts;
  227. ReplaceStr(s,';',' ');
  228. { add "" for args with spaces }
  229. { WARNING : text must still be entered in usual grep syntax }
  230. { -n is always added later because otherwise
  231. we don't get the line info PM }
  232. GrepArgs:=' -i "$TEXT" '+s;
  233. { Dialog }
  234. R.Assign(0,0,50,8);
  235. new(PGrepDialog,Init(R,dialog_greparguments));
  236. with PGrepDialog^ do
  237. begin
  238. R2.A.Y:=R.A.Y+3;
  239. R2.B.Y:=R2.A.Y+1;
  240. R2.A.X:=R.A.X+3;
  241. R2.B.X:=R.B.X-6;
  242. New(IL1, Init(R2, 128));
  243. IL1^.Data^:=SearchWord;
  244. Insert(IL1);
  245. R2.Move(0,-1);
  246. Insert(New(PLabel, Init(R2, label_grep_texttofind, IL1)));
  247. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  248. Control := New(PHistory, Init(R1, IL1, TextGrepId));
  249. Insert(Control);
  250. R2.Move(0,4);
  251. New(IL2, Init(R2, 128));
  252. IL2^.Data^:=GrepArgs;
  253. Insert(IL2);
  254. R2.Move(0,-1);
  255. Insert(New(PLabel, Init(R2, label_grep_greparguments, IL2)));
  256. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  257. Control := New(PHistory, Init(R1, IL2, GrepArgsId));
  258. Insert(Control);
  259. end;
  260. InsertButtons(PGrepDialog);
  261. IL1^.Select;
  262. if Desktop^.ExecView(PGrepDialog)=cmOK then
  263. begin
  264. SearchWord:=IL1^.Data^;
  265. if SearchWord<>'' then
  266. begin
  267. GrepArgs:=IL2^.Data^;
  268. { Remember last used Grep extensions }
  269. PosText:=pos('"$TEXT" ',GrepArgs);
  270. if PosText>0 then
  271. HighlightExts:=Trim(Copy(GrepArgs,PosText+Length('"$TEXT" '),Length(GrepArgs)));
  272. { change spaces back into ';' again }
  273. ReplaceStr(HighlightExts,' ',';');
  274. { Replace search string }
  275. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  276. { Linux ? }
  277. AddToolCommand(GrepExe+' -n '+GrepArgs);
  278. ToFocus:=ToolMessages^.count-1;
  279. UpdateToolMessages;
  280. if Assigned(MessagesWindow) then
  281. MessagesWindow^.FocusItem(ToFocus);
  282. showmsg:=true;
  283. Messages;
  284. PushStatus(FormatStrStr(msg_runninggrepwithargs,GrepArgs));
  285. if not ExecuteRedir(GrepExe,'-n '+GrepArgs,'',GrepOutName,GrepErrName) then
  286. Begin
  287. PopStatus;
  288. { 2 as exit code just means that
  289. some file vwere not found ! }
  290. if (IOStatus<>0) or (ExecuteResult<>2) then
  291. begin
  292. Params[0]:=IOStatus;
  293. Params[1]:=ExecuteResult;
  294. WarningBox(msg_errorrunninggrep,@Params);
  295. end;
  296. End
  297. else
  298. PopStatus;
  299. {$I-}
  300. Assign(GrepOut,GrepOutName);
  301. Reset(GrepOut);
  302. error_in_reading:=false;
  303. FirstMsg:=True;
  304. GrepOutputLine:=0;
  305. While not eof(GrepOut) do
  306. begin
  307. readln(GrepOut,Line);
  308. Inc(GrepOutputLine);
  309. p:=pos(':',line);
  310. if p>0 then
  311. begin
  312. ModuleName:=copy(Line,1,p-1);
  313. Line:=Copy(Line,p+1,255);
  314. p:=pos(':',Line);
  315. val(copy(Line,1,p-1),lineNb,error);
  316. if error=0 then
  317. begin
  318. AddToolMessage(ModuleName,Copy(Line,p+1,255),LineNb,1);
  319. if FirstMsg then
  320. begin
  321. Inc(ToFocus);
  322. FirstMsg:=false;
  323. end;
  324. end
  325. else
  326. error_in_reading:=true;
  327. end;
  328. end;
  329. Close(GrepOut);
  330. if not error_in_reading then
  331. Erase(GrepOut)
  332. else
  333. begin
  334. ClearFormatParams;
  335. AddFormatParamInt(GrepOutputLine);
  336. AddFormatParamStr(GrepOutName);
  337. WarningBox(msg_errorreadinggrepoutput,@FormatParams);
  338. end;
  339. { Delete also grep$$.err }
  340. if not error_in_reading then
  341. begin
  342. Assign(GrepOut,GrepErrName);
  343. Erase(GrepOut);
  344. end;
  345. {$I+}
  346. EatIO;
  347. end;
  348. end;
  349. Dispose(PGrepDialog, Done);
  350. UpdateToolMessages;
  351. if (ToFocus<>-1) then
  352. if Assigned(MessagesWindow) then
  353. begin
  354. MessagesWindow^.Lock;
  355. MessagesWindow^.FocusItem(ToolMessages^.count-1);
  356. if ToFocus>0 then
  357. MessagesWindow^.FocusItem(ToFocus-1);
  358. MessagesWindow^.FocusItem(ToFocus);
  359. MessagesWindow^.UnLock;
  360. end;
  361. if showmsg then
  362. Messages;
  363. end;