fpintf.pas 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Misc routines for the IDE
  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. {$i globdir.inc}
  13. unit FPIntf;
  14. {$mode objfpc}
  15. interface
  16. { Run }
  17. function GetRunParameters: string;
  18. procedure SetRunParameters(const Params: string);
  19. function GetRunDir: string;
  20. procedure SetRunDir(const Params: string);
  21. { Compile }
  22. procedure Compile(const FileName, ConfigFile: string);
  23. procedure SetPrimaryFile(const fn:string);
  24. function LinkAfter : boolean;
  25. {$ifdef USE_EXTERNAL_COMPILER}
  26. function version_string : string;
  27. {$endif USE_EXTERNAL_COMPILER}
  28. implementation
  29. uses
  30. Compiler,Comphook,
  31. sysutils,
  32. {$ifndef NODEBUG}
  33. FPDebug,
  34. {$endif NODEBUG}
  35. FPRedir,FPVars,FpCompil,
  36. FPUtils,FPSwitch,WUtils;
  37. {****************************************************************************
  38. Run
  39. ****************************************************************************}
  40. var
  41. RunDir,
  42. RunParameters : string;
  43. function LinkAfter : boolean;
  44. begin
  45. LinkAfter:=LinkAfterSwitches^.GetBooleanItem(0);
  46. end;
  47. function GetRunParameters: string;
  48. begin
  49. GetRunParameters:=RunParameters;
  50. end;
  51. procedure SetRunParameters(const Params: string);
  52. begin
  53. RunParameters:=Params;
  54. {$ifndef NODEBUG}
  55. If assigned(Debugger) then
  56. Debugger^.SetArgs(RunParameters);
  57. {$endif}
  58. end;
  59. function GetRunDir: string;
  60. begin
  61. GetRunDir:=RunDir;
  62. end;
  63. procedure SetRunDir(const Params: string);
  64. begin
  65. RunDir:=Params;
  66. {$ifndef NODEBUG}
  67. If assigned(Debugger) then
  68. Debugger^.SetDir(RunDir);
  69. {$endif}
  70. end;
  71. {****************************************************************************
  72. Compile
  73. ****************************************************************************}
  74. var
  75. CatchErrorLongJumpBuffer : jmp_buf;
  76. procedure CatchCompilationErrors;
  77. begin
  78. LongJmp(CatchErrorLongJumpBuffer,1);
  79. end;
  80. procedure Compile(const FileName, ConfigFile: string);
  81. var
  82. cmd : string;
  83. ExitReason : integer;
  84. ExitAddr,StoreExitProc : pointer;
  85. {$ifdef USE_EXTERNAL_COMPILER}
  86. CompilerOut : Text;
  87. CompilerOutputLine : longint;
  88. V,p,p1,p2,lineNb,ColumnNb : longint;
  89. error : word;
  90. ModuleName,Line : string;
  91. error_in_reading : boolean;
  92. {$endif USE_EXTERNAL_COMPILER}
  93. begin
  94. {$ifndef USE_EXTERNAL_COMPILER}
  95. cmd:='-d'+SwitchesModeStr[SwitchesMode];
  96. if ConfigFile<>'' then
  97. cmd:='['+ConfigFile+'] '+cmd;
  98. {$else USE_EXTERNAL_COMPILER}
  99. cmd:='-n -d'+SwitchesModeStr[SwitchesMode];
  100. if ConfigFile<>'' then
  101. cmd:='@'+ConfigFile+' '+cmd;
  102. if not UseExternalCompiler then
  103. {$endif USE_EXTERNAL_COMPILER}
  104. { Add the switches from the primary file }
  105. if PrimaryFileSwitches<>'' then
  106. cmd:=cmd+' '+PrimaryFileSwitches;
  107. cmd:=cmd+' '+FileName;
  108. { call the compiler }
  109. {$ifdef USE_EXTERNAL_COMPILER}
  110. if UseExternalCompiler then
  111. begin
  112. If not LocateExeFile(ExternalCompilerExe) then
  113. begin
  114. CompilerMessageWindow^.AddMessage(
  115. 0,ExternalCompilerExe+' not found','',0,0);
  116. exit;
  117. end;
  118. CompilerMessageWindow^.AddMessage(
  119. 0,'Running: '+ExternalCompilerExe+' '+cmd,'',0,0);
  120. if not ExecuteRedir(ExternalCompilerExe,cmd,'','ppc___.out','ppc___.err') then
  121. begin
  122. CompilerMessageWindow^.AddMessage(
  123. V_error,msg_errorinexternalcompilation,'',0,0);
  124. CompilerMessageWindow^.AddMessage(
  125. V_error,FormatStrInt(msg_iostatusis,IOStatus),'',0,0);
  126. CompilerMessageWindow^.AddMessage(
  127. V_error,FormatStrInt(msg_executeresultis,ExecuteResult),'',0,0);
  128. if IOStatus<>0 then
  129. exit;
  130. end;
  131. Assign(CompilerOut,'ppc___.out');
  132. Reset(CompilerOut);
  133. error_in_reading:=false;
  134. CompilerOutputLine:=0;
  135. While not eof(CompilerOut) do
  136. begin
  137. readln(CompilerOut,Line);
  138. Inc(CompilerOutputLine);
  139. p:=pos('(',line);
  140. if p>0 then
  141. begin
  142. ModuleName:=copy(Line,1,p-1);
  143. Line:=Copy(Line,p+1,255);
  144. p1:=pos(',',Line);
  145. val(copy(Line,1,p1-1),lineNb,error);
  146. Line:=Copy(Line,p1+1,255);
  147. p2:=pos(')',Line);
  148. if error=0 then
  149. val(copy(Line,1,p2-1),ColumnNb,error);
  150. Line:=Copy(Line,p2+1,255);
  151. V:=0;
  152. { using constants here isn't a good idea, because this won't
  153. work with localized versions of the compiler - Gabor }
  154. If Pos(' Error:',line)=1 then
  155. begin
  156. V:=V_error;
  157. Line:=Copy(Line,8,Length(Line));
  158. end
  159. else if Pos(' Fatal:',line)=1 then
  160. begin
  161. V:=V_fatal;
  162. Line:=Copy(Line,8,Length(Line));
  163. end
  164. else if Pos(' Hint:',line)=1 then
  165. begin
  166. V:=V_hint;
  167. Line:=Copy(Line,7,Length(Line));
  168. end
  169. else if Pos(' Note:',line)=1 then
  170. begin
  171. V:=V_note;
  172. Line:=Copy(Line,7,Length(Line));
  173. end;
  174. if error=0 then
  175. CompilerMessageWindow^.AddMessage(V,Line,ModuleName,LineNb,ColumnNb)
  176. else
  177. error_in_reading:=true;
  178. end
  179. else
  180. CompilerMessageWindow^.AddMessage(0,Line,'',0,0);
  181. ;
  182. end;
  183. Close(CompilerOut);
  184. end
  185. else
  186. {$endif USE_EXTERNAL_COMPILER}
  187. begin
  188. try
  189. Compiler.Compile(cmd);
  190. except
  191. on e : exception do
  192. begin
  193. CompilationPhase:=cpFailed;
  194. CompilerMessageWindow^.AddMessage(V_Error,
  195. 'Compiler exited','',0,0);
  196. CompilerMessageWindow^.AddMessage(V_Error,
  197. e.message,'',0,0);
  198. end;
  199. end;
  200. end;
  201. end;
  202. {$ifdef USE_EXTERNAL_COMPILER}
  203. function version_string : string;
  204. begin
  205. if not ExecuteRedir(ExternalCompilerExe,'-iV','','ppc___.out','ppc___.err') then
  206. version_string:=version.version_string;
  207. Assign(CompilerOut,'ppc___.out');
  208. Reset(CompilerOut);
  209. Readln(CompilerOut,s);
  210. Close(CompilerOut);
  211. version_string:=s;
  212. end;
  213. {$endif USE_EXTERNAL_COMPILER}
  214. procedure SetPrimaryFile(const fn:string);
  215. var
  216. t : text;
  217. begin
  218. PrimaryFile:='';
  219. PrimaryFileMain:='';
  220. PrimaryFileSwitches:='';
  221. PrimaryFilePara:='';
  222. if UpcaseStr(ExtOf(fn))='.PRI' then
  223. begin
  224. assign(t,fn);
  225. {$I-}
  226. reset(t);
  227. if ioresult=0 then
  228. begin
  229. PrimaryFile:=fn;
  230. readln(t,PrimaryFileMain);
  231. readln(t,PrimaryFileSwitches);
  232. readln(t,PrimaryFilePara);
  233. close(t);
  234. end;
  235. {$I+}
  236. EatIO;
  237. end
  238. else
  239. begin
  240. PrimaryFile:=fn;
  241. PrimaryFileMain:=fn;
  242. end;
  243. if PrimaryFilePara<>'' then
  244. SetRunParameters(PrimaryFilePara);
  245. end;
  246. end.
  247. {
  248. $Log$
  249. Revision 1.6 2004-11-08 20:28:26 peter
  250. * Breakpoints are now deleted when removed from source, disabling is
  251. still possible from the breakpoint list
  252. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  253. FV and 1.9.x compilers
  254. * Run directory added to Run menu
  255. * Useless programinfo window removed
  256. Revision 1.5 2002/10/04 15:23:46 pierre
  257. * don't use tpexcept anymore
  258. Revision 1.4 2002/09/07 15:40:43 peter
  259. * old logs removed and tabs fixed
  260. }