fpintf.pas 7.1 KB

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