fpintf.pas 7.9 KB

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