fpintf.pas 7.5 KB

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