fpintf.pas 8.4 KB

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