fpintf.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. {$ifdef FPC}
  15. {$ifndef COMPILER_1_0}
  16. {$mode objfpc}
  17. {$endif COMPILER_1_0}
  18. {$endif FPC}
  19. interface
  20. { Run }
  21. function GetRunParameters: string;
  22. procedure SetRunParameters(const Params: string);
  23. { Compile }
  24. procedure Compile(const FileName, ConfigFile: string);
  25. procedure SetPrimaryFile(const fn:string);
  26. function LinkAfter : boolean;
  27. {$ifdef USE_EXTERNAL_COMPILER}
  28. function version_string : string;
  29. {$endif USE_EXTERNAL_COMPILER}
  30. implementation
  31. uses
  32. Compiler,Comphook,
  33. {$ifdef FPC}
  34. {$ifndef COMPILER_1_0}
  35. sysutils,
  36. {$endif COMPILER_1_0}
  37. {$endif FPC}
  38. {$ifdef COMPILER_1_0}
  39. tpexcept,
  40. {$endif COMPILER_1_0}
  41. {$ifndef NODEBUG}
  42. FPDebug,
  43. {$endif NODEBUG}
  44. FPRedir,FPVars,FpCompil,
  45. FPUtils,FPSwitch,WUtils;
  46. {****************************************************************************
  47. Run
  48. ****************************************************************************}
  49. var
  50. RunParameters : string;
  51. function LinkAfter : boolean;
  52. begin
  53. LinkAfter:=LinkAfterSwitches^.GetBooleanItem(0);
  54. end;
  55. function GetRunParameters: string;
  56. begin
  57. GetRunParameters:=RunParameters;
  58. end;
  59. procedure SetRunParameters(const Params: string);
  60. begin
  61. RunParameters:=Params;
  62. {$ifndef NODEBUG}
  63. If assigned(Debugger) then
  64. Debugger^.SetArgs(RunParameters);
  65. {$endif}
  66. end;
  67. {****************************************************************************
  68. Compile
  69. ****************************************************************************}
  70. var
  71. CatchErrorLongJumpBuffer : jmp_buf;
  72. procedure CatchCompilationErrors;
  73. begin
  74. LongJmp(CatchErrorLongJumpBuffer,1);
  75. end;
  76. procedure Compile(const FileName, ConfigFile: string);
  77. var
  78. cmd : string;
  79. ExitReason : integer;
  80. ExitAddr,StoreExitProc : pointer;
  81. {$ifdef USE_EXTERNAL_COMPILER}
  82. CompilerOut : Text;
  83. CompilerOutputLine : longint;
  84. V,p,p1,p2,lineNb,ColumnNb : longint;
  85. error : word;
  86. ModuleName,Line : string;
  87. error_in_reading : boolean;
  88. {$endif USE_EXTERNAL_COMPILER}
  89. begin
  90. {$ifndef USE_EXTERNAL_COMPILER}
  91. cmd:='-d'+SwitchesModeStr[SwitchesMode];
  92. if ConfigFile<>'' then
  93. cmd:='['+ConfigFile+'] '+cmd;
  94. {$else USE_EXTERNAL_COMPILER}
  95. cmd:='-n -d'+SwitchesModeStr[SwitchesMode];
  96. if ConfigFile<>'' then
  97. cmd:='@'+ConfigFile+' '+cmd;
  98. if not UseExternalCompiler then
  99. {$endif USE_EXTERNAL_COMPILER}
  100. { Add the switches from the primary file }
  101. if PrimaryFileSwitches<>'' then
  102. cmd:=cmd+' '+PrimaryFileSwitches;
  103. cmd:=cmd+' '+FileName;
  104. { call the compiler }
  105. {$ifdef USE_EXTERNAL_COMPILER}
  106. if UseExternalCompiler then
  107. begin
  108. If not LocateExeFile(ExternalCompilerExe) then
  109. begin
  110. CompilerMessageWindow^.AddMessage(
  111. 0,ExternalCompilerExe+' not found','',0,0);
  112. exit;
  113. end;
  114. CompilerMessageWindow^.AddMessage(
  115. 0,'Running: '+ExternalCompilerExe+' '+cmd,'',0,0);
  116. if not ExecuteRedir(ExternalCompilerExe,cmd,'','ppc___.out','ppc___.err') then
  117. begin
  118. CompilerMessageWindow^.AddMessage(
  119. V_error,msg_errorinexternalcompilation,'',0,0);
  120. CompilerMessageWindow^.AddMessage(
  121. V_error,FormatStrInt(msg_iostatusis,IOStatus),'',0,0);
  122. CompilerMessageWindow^.AddMessage(
  123. V_error,FormatStrInt(msg_executeresultis,ExecuteResult),'',0,0);
  124. if IOStatus<>0 then
  125. exit;
  126. end;
  127. Assign(CompilerOut,'ppc___.out');
  128. Reset(CompilerOut);
  129. error_in_reading:=false;
  130. CompilerOutputLine:=0;
  131. While not eof(CompilerOut) do
  132. begin
  133. readln(CompilerOut,Line);
  134. Inc(CompilerOutputLine);
  135. p:=pos('(',line);
  136. if p>0 then
  137. begin
  138. ModuleName:=copy(Line,1,p-1);
  139. Line:=Copy(Line,p+1,255);
  140. p1:=pos(',',Line);
  141. val(copy(Line,1,p1-1),lineNb,error);
  142. Line:=Copy(Line,p1+1,255);
  143. p2:=pos(')',Line);
  144. if error=0 then
  145. val(copy(Line,1,p2-1),ColumnNb,error);
  146. Line:=Copy(Line,p2+1,255);
  147. V:=0;
  148. { using constants here isn't a good idea, because this won't
  149. work with localized versions of the compiler - Gabor }
  150. If Pos(' Error:',line)=1 then
  151. begin
  152. V:=V_error;
  153. Line:=Copy(Line,8,Length(Line));
  154. end
  155. else if Pos(' Fatal:',line)=1 then
  156. begin
  157. V:=V_fatal;
  158. Line:=Copy(Line,8,Length(Line));
  159. end
  160. else if Pos(' Hint:',line)=1 then
  161. begin
  162. V:=V_hint;
  163. Line:=Copy(Line,7,Length(Line));
  164. end
  165. else if Pos(' Note:',line)=1 then
  166. begin
  167. V:=V_note;
  168. Line:=Copy(Line,7,Length(Line));
  169. end;
  170. if error=0 then
  171. CompilerMessageWindow^.AddMessage(V,Line,ModuleName,LineNb,ColumnNb)
  172. else
  173. error_in_reading:=true;
  174. end
  175. else
  176. CompilerMessageWindow^.AddMessage(0,Line,'',0,0);
  177. ;
  178. end;
  179. Close(CompilerOut);
  180. end
  181. else
  182. {$endif USE_EXTERNAL_COMPILER}
  183. begin
  184. {$ifdef COMPILER_1_0}
  185. storeexitproc:=exitproc;
  186. if SetJmp(CatchErrorLongJumpBuffer)=0 then
  187. begin
  188. exitproc:=@CatchCompilationErrors;
  189. {$else : not COMPILER_1_0}
  190. try
  191. {$endif COMPILER_1_0}
  192. Compiler.Compile(cmd);
  193. {$ifdef COMPILER_1_0}
  194. end
  195. else
  196. begin
  197. ExitReason:=ExitCode;
  198. ExitCode:=0;
  199. ErrorCode:=0;
  200. ExitAddr:=ErrorAddr;
  201. ErrorAddr:=nil;
  202. CompilationPhase:=cpFailed;
  203. { FIXME: this is not 64bit compatible PM }
  204. CompilerMessageWindow^.AddMessage(V_Error,
  205. 'Compiler exited with error '+inttostr(ExitReason)+
  206. ' at addr '+inttohex(longint(ExitAddr),8),'',0,0);
  207. end;
  208. exitproc:=storeexitproc;
  209. {$else : not COMPILER_1_0}
  210. except
  211. on e : exception do
  212. begin
  213. CompilationPhase:=cpFailed;
  214. CompilerMessageWindow^.AddMessage(V_Error,
  215. 'Compiler exited','',0,0);
  216. CompilerMessageWindow^.AddMessage(V_Error,
  217. e.message,'',0,0);
  218. end;
  219. end;
  220. {$endif COMPILER_1_0}
  221. end;
  222. end;
  223. {$ifdef USE_EXTERNAL_COMPILER}
  224. function version_string : string;
  225. begin
  226. if not ExecuteRedir(ExternalCompilerExe,'-iV','','ppc___.out','ppc___.err') then
  227. version_string:=version.version_string;
  228. Assign(CompilerOut,'ppc___.out');
  229. Reset(CompilerOut);
  230. Readln(CompilerOut,s);
  231. Close(CompilerOut);
  232. version_string:=s;
  233. end;
  234. {$endif USE_EXTERNAL_COMPILER}
  235. procedure SetPrimaryFile(const fn:string);
  236. var
  237. t : text;
  238. begin
  239. PrimaryFile:='';
  240. PrimaryFileMain:='';
  241. PrimaryFileSwitches:='';
  242. PrimaryFilePara:='';
  243. if UpcaseStr(ExtOf(fn))='.PRI' then
  244. begin
  245. assign(t,fn);
  246. {$I-}
  247. reset(t);
  248. if ioresult=0 then
  249. begin
  250. PrimaryFile:=fn;
  251. readln(t,PrimaryFileMain);
  252. readln(t,PrimaryFileSwitches);
  253. readln(t,PrimaryFilePara);
  254. close(t);
  255. end;
  256. {$I+}
  257. EatIO;
  258. end
  259. else
  260. begin
  261. PrimaryFile:=fn;
  262. PrimaryFileMain:=fn;
  263. end;
  264. if PrimaryFilePara<>'' then
  265. SetRunParameters(PrimaryFilePara);
  266. end;
  267. end.
  268. {
  269. $Log$
  270. Revision 1.3 2001-10-03 20:46:34 pierre
  271. * except syntax fix for 1.1 version
  272. Revision 1.2 2001/10/03 10:21:43 pierre
  273. fix for bug 1487
  274. Revision 1.1 2001/08/04 11:30:23 peter
  275. * ide works now with both compiler versions
  276. Revision 1.1.2.3 2001/03/08 16:40:07 pierre
  277. + version_string function from external compiler
  278. Revision 1.1.2.2 2000/11/14 17:40:43 pierre
  279. + External linking now optional
  280. Revision 1.1.2.1 2000/11/13 16:59:09 pierre
  281. * some function in double removed from fputils unit
  282. Revision 1.1 2000/07/13 09:48:35 michael
  283. + Initial import
  284. Revision 1.12 2000/06/22 09:07:12 pierre
  285. * Gabor changes: see fixes.txt
  286. Revision 1.11 2000/05/29 10:44:56 pierre
  287. + New bunch of Gabor's changes: see fixes.txt
  288. Revision 1.10 2000/05/02 08:42:27 pierre
  289. * new set of Gabor changes: see fixes.txt
  290. Revision 1.9 2000/03/01 22:37:25 pierre
  291. + USE_EXTERNAL_COMPILER
  292. Revision 1.8 2000/01/03 11:38:34 michael
  293. Changes from Gabor
  294. Revision 1.7 1999/09/16 14:34:59 pierre
  295. + TBreakpoint and TWatch registering
  296. + WatchesCollection and BreakpointsCollection stored in desk file
  297. * Syntax highlighting was broken
  298. Revision 1.6 1999/06/30 23:58:15 pierre
  299. + BreakpointsList Window implemented
  300. with Edit/New/Delete functions
  301. + Individual breakpoint dialog with support for all types
  302. ignorecount and conditions
  303. (commands are not yet implemented, don't know if this wolud be useful)
  304. awatch and rwatch have problems because GDB does not annotate them
  305. I fixed v4.16 for this
  306. Revision 1.5 1999/06/21 23:38:37 pierre
  307. + support for LinkAfter var
  308. Revision 1.4 1999/03/12 01:12:22 peter
  309. * extended primaryfile to load a .pri file
  310. Revision 1.3 1999/02/05 13:51:41 peter
  311. * unit name of FPSwitches -> FPSwitch which is easier to use
  312. * some fixes for tp7 compiling
  313. Revision 1.2 1998/12/28 15:47:45 peter
  314. + Added user screen support, display & window
  315. + Implemented Editor,Mouse Options dialog
  316. + Added location of .INI and .CFG file
  317. + Option (INI) file managment implemented (see bottom of Options Menu)
  318. + Switches updated
  319. + Run program
  320. Revision 1.1 1998/12/22 14:27:54 peter
  321. * moved
  322. Revision 1.4 1998/12/22 10:39:43 peter
  323. + options are now written/read
  324. + find and replace routines
  325. }