fpmtools.inc 11 KB

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