fpintf.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. interface
  15. { Run }
  16. function GetRunParameters: string;
  17. procedure SetRunParameters(const Params: string);
  18. { Compile }
  19. procedure Compile(const FileName: string);
  20. procedure SetPrimaryFile(const fn:string);
  21. implementation
  22. uses
  23. Compiler,CompHook,
  24. {$ifndef NODEBUG}
  25. FPDebug,
  26. {$endif NODEBUG}
  27. FPCompile,FPRedir,FPVars,
  28. FPUtils,FPSwitch;
  29. {****************************************************************************
  30. Run
  31. ****************************************************************************}
  32. var
  33. RunParameters : string;
  34. function GetRunParameters: string;
  35. begin
  36. GetRunParameters:=RunParameters;
  37. end;
  38. procedure SetRunParameters(const Params: string);
  39. begin
  40. RunParameters:=Params;
  41. {$ifndef NODEBUG}
  42. If assigned(Debugger) then
  43. Debugger^.SetArgs(RunParameters);
  44. {$endif}
  45. end;
  46. {****************************************************************************
  47. Compile
  48. ****************************************************************************}
  49. procedure Compile(const FileName: string);
  50. var
  51. cmd : string;
  52. {$ifdef USE_EXTERNAL_COMPILER}
  53. CompilerOut : Text;
  54. CompilerOutputLine : longint;
  55. V,p,p1,p2,lineNb,ColumnNb : longint;
  56. error : word;
  57. ModuleName,Line : string;
  58. error_in_reading : boolean;
  59. {$endif USE_EXTERNAL_COMPILER}
  60. begin
  61. {$ifndef USE_EXTERNAL_COMPILER}
  62. cmd:='[fp.cfg] -d'+SwitchesModeStr[SwitchesMode];
  63. {$else USE_EXTERNAL_COMPILER}
  64. cmd:='-n @fp.cfg -d'+SwitchesModeStr[SwitchesMode];
  65. if not UseExternalCompiler then
  66. {$endif USE_EXTERNAL_COMPILER}
  67. if LinkAfter then
  68. cmd:=cmd+' -s';
  69. { Add the switches from the primary file }
  70. if PrimaryFileSwitches<>'' then
  71. cmd:=cmd+' '+PrimaryFileSwitches;
  72. cmd:=cmd+' '+FileName;
  73. { call the compiler }
  74. {$ifdef USE_EXTERNAL_COMPILER}
  75. if UseExternalCompiler then
  76. begin
  77. If not LocateExeFile(ExternalCompilerExe) then
  78. begin
  79. CompilerMessageWindow^.AddMessage(
  80. 0,ExternalCompilerExe+' not found','',0,0);
  81. exit;
  82. end;
  83. CompilerMessageWindow^.AddMessage(
  84. 0,'Running: '+ExternalCompilerExe+' '+cmd,'',0,0);
  85. if not ExecuteRedir(ExternalCompilerExe,cmd,'','ppc___.out','ppc___.err') then
  86. begin
  87. CompilerMessageWindow^.AddMessage(
  88. V_error,msg_errorinexternalcompilation,'',0,0);
  89. CompilerMessageWindow^.AddMessage(
  90. V_error,FormatStrInt(msg_iostatusis,IOStatus),'',0,0);
  91. CompilerMessageWindow^.AddMessage(
  92. V_error,FormatStrInt(msg_executeresultis,ExecuteResult),'',0,0);
  93. if IOStatus<>0 then
  94. exit;
  95. end;
  96. Assign(CompilerOut,'ppc___.out');
  97. Reset(CompilerOut);
  98. error_in_reading:=false;
  99. CompilerOutputLine:=0;
  100. While not eof(CompilerOut) do
  101. begin
  102. readln(CompilerOut,Line);
  103. Inc(CompilerOutputLine);
  104. p:=pos('(',line);
  105. if p>0 then
  106. begin
  107. ModuleName:=copy(Line,1,p-1);
  108. Line:=Copy(Line,p+1,255);
  109. p1:=pos(',',Line);
  110. val(copy(Line,1,p1-1),lineNb,error);
  111. Line:=Copy(Line,p1+1,255);
  112. p2:=pos(')',Line);
  113. if error=0 then
  114. val(copy(Line,1,p2-1),ColumnNb,error);
  115. Line:=Copy(Line,p2+1,255);
  116. V:=0;
  117. { using constants here isn't a good idea, because this won't
  118. work with localized versions of the compiler - Gabor }
  119. If Pos(' Error:',line)=1 then
  120. begin
  121. V:=V_error;
  122. Line:=Copy(Line,8,Length(Line));
  123. end
  124. else if Pos(' Fatal:',line)=1 then
  125. begin
  126. V:=V_fatal;
  127. Line:=Copy(Line,8,Length(Line));
  128. end
  129. else if Pos(' Hint:',line)=1 then
  130. begin
  131. V:=V_hint;
  132. Line:=Copy(Line,7,Length(Line));
  133. end
  134. else if Pos(' Note:',line)=1 then
  135. begin
  136. V:=V_note;
  137. Line:=Copy(Line,7,Length(Line));
  138. end;
  139. if error=0 then
  140. CompilerMessageWindow^.AddMessage(V,Line,ModuleName,LineNb,ColumnNb)
  141. else
  142. error_in_reading:=true;
  143. end
  144. else
  145. CompilerMessageWindow^.AddMessage(0,Line,'',0,0);
  146. ;
  147. end;
  148. Close(CompilerOut);
  149. end
  150. else
  151. {$endif USE_EXTERNAL_COMPILER}
  152. Compiler.Compile(cmd);
  153. end;
  154. procedure SetPrimaryFile(const fn:string);
  155. var
  156. t : text;
  157. begin
  158. PrimaryFile:='';
  159. PrimaryFileMain:='';
  160. PrimaryFileSwitches:='';
  161. PrimaryFilePara:='';
  162. if UpcaseStr(ExtOf(fn))='.PRI' then
  163. begin
  164. assign(t,fn);
  165. {$I-}
  166. reset(t);
  167. if ioresult=0 then
  168. begin
  169. PrimaryFile:=fn;
  170. readln(t,PrimaryFileMain);
  171. readln(t,PrimaryFileSwitches);
  172. readln(t,PrimaryFilePara);
  173. close(t);
  174. end;
  175. {$I+}
  176. EatIO;
  177. end
  178. else
  179. begin
  180. PrimaryFile:=fn;
  181. PrimaryFileMain:=fn;
  182. end;
  183. if PrimaryFilePara<>'' then
  184. SetRunParameters(PrimaryFilePara);
  185. end;
  186. end.
  187. {
  188. $Log$
  189. Revision 1.10 2000-05-02 08:42:27 pierre
  190. * new set of Gabor changes: see fixes.txt
  191. Revision 1.9 2000/03/01 22:37:25 pierre
  192. + USE_EXTERNAL_COMPILER
  193. Revision 1.8 2000/01/03 11:38:34 michael
  194. Changes from Gabor
  195. Revision 1.7 1999/09/16 14:34:59 pierre
  196. + TBreakpoint and TWatch registering
  197. + WatchesCollection and BreakpointsCollection stored in desk file
  198. * Syntax highlighting was broken
  199. Revision 1.6 1999/06/30 23:58:15 pierre
  200. + BreakpointsList Window implemented
  201. with Edit/New/Delete functions
  202. + Individual breakpoint dialog with support for all types
  203. ignorecount and conditions
  204. (commands are not yet implemented, don't know if this wolud be useful)
  205. awatch and rwatch have problems because GDB does not annotate them
  206. I fixed v4.16 for this
  207. Revision 1.5 1999/06/21 23:38:37 pierre
  208. + support for LinkAfter var
  209. Revision 1.4 1999/03/12 01:12:22 peter
  210. * extended primaryfile to load a .pri file
  211. Revision 1.3 1999/02/05 13:51:41 peter
  212. * unit name of FPSwitches -> FPSwitch which is easier to use
  213. * some fixes for tp7 compiling
  214. Revision 1.2 1998/12/28 15:47:45 peter
  215. + Added user screen support, display & window
  216. + Implemented Editor,Mouse Options dialog
  217. + Added location of .INI and .CFG file
  218. + Option (INI) file managment implemented (see bottom of Options Menu)
  219. + Switches updated
  220. + Run program
  221. Revision 1.1 1998/12/22 14:27:54 peter
  222. * moved
  223. Revision 1.4 1998/12/22 10:39:43 peter
  224. + options are now written/read
  225. + find and replace routines
  226. }