fpcompil.pas 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Compiler call 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. unit FPCompile;
  13. interface
  14. uses FPViews;
  15. type
  16. TCompileMode = (cBuild,cMake,cCompile,cRun);
  17. PCompileStatusDialog = ^TCompileStatusDialog;
  18. TCompileStatusDialog = object(TCenterDialog)
  19. ST : PAdvancedStaticText;
  20. KeyST : PColorStaticText;
  21. constructor Init;
  22. procedure Update;
  23. private
  24. MsgLB: PMessageListBox;
  25. end;
  26. procedure DoCompile(Mode: TCompileMode);
  27. const SD: PCompileStatusDialog = nil;
  28. implementation
  29. uses
  30. Dos,Video,
  31. Objects,Drivers,Views,App,Commands,
  32. CompHook,
  33. {$ifdef go32v2}
  34. FPRedir,
  35. {$endif def go32v2}
  36. FPConst,FPVars,FPUtils,FPIntf,FPSwitch;
  37. constructor TCompileStatusDialog.Init;
  38. var R: TRect;
  39. begin
  40. R.Assign(0,0,50,11+7);
  41. inherited Init(R, 'Compiling');
  42. GetExtent(R); R.B.Y:=11;
  43. R.Grow(-3,-2);
  44. New(ST, Init(R, ''));
  45. Insert(ST);
  46. GetExtent(R); R.B.Y:=11;
  47. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  48. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256));
  49. Insert(KeyST);
  50. GetExtent(R); R.Grow(-1,-1); R.A.Y:=10;
  51. New(MsgLB, Init(R, nil, nil));
  52. Insert(MsgLB);
  53. end;
  54. procedure TCompileStatusDialog.Update;
  55. var StatusS,KeyS: string;
  56. const CtrlBS = 'Press Ctrl+Break to cancel';
  57. SuccessS = 'Compile successful: ~Press Enter~';
  58. FailS = 'Compile failed';
  59. begin
  60. {$ifdef TEMPHEAP}
  61. switch_to_base_heap;
  62. {$endif TEMPHEAP}
  63. case CompilationPhase of
  64. cpCompiling :
  65. begin
  66. StatusS:='Compiling '+Status.CurrentSource;
  67. KeyS:=CtrlBS;
  68. end;
  69. cpLinking :
  70. begin
  71. StatusS:='Linking...';
  72. KeyS:=CtrlBS;
  73. end;
  74. cpDone :
  75. begin
  76. StatusS:='Done.';
  77. KeyS:=SuccessS;
  78. end;
  79. cpFailed :
  80. begin
  81. StatusS:='Failed to compile...';
  82. KeyS:=FailS;
  83. end;
  84. end;
  85. ST^.SetText(
  86. 'Main file: '+SmartPath(MainFile)+#13+
  87. StatusS+#13#13+
  88. 'Target: '+LExpand(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),12)+' '+
  89. 'Line number: '+IntToStrL(Status.CurrentLine,7)+#13+
  90. 'Free memory: '+IntToStrL(MemAvail div 1024,6)+'K'+ ' '+
  91. 'Total lines: '+IntToStrL(Status.CompiledLines,7)+#13+
  92. 'Total errors: '+IntToStrL(Status.ErrorCount,5)
  93. );
  94. KeyST^.SetText(^C+KeyS);
  95. {$ifdef TEMPHEAP}
  96. switch_to_temp_heap;
  97. {$endif TEMPHEAP}
  98. end;
  99. {****************************************************************************
  100. Compiler Hooks
  101. ****************************************************************************}
  102. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  103. begin
  104. if SD<>nil then SD^.Update;
  105. CompilerStatus:=false;
  106. end;
  107. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  108. begin
  109. end;
  110. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  111. begin
  112. {$ifdef TEMPHEAP}
  113. switch_to_base_heap;
  114. {$endif TEMPHEAP}
  115. CompilerComment:=false;
  116. {$ifndef DEV}
  117. if (status.verbosity and Level)=Level then
  118. {$endif}
  119. begin
  120. ProgramInfoWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,status.currentline);
  121. if SD<>nil then
  122. SD^.MsgLB^.AddItem(New(PCompilerMessage, Init(Level, S, SmartPath(status.currentmodule),status.currentline)));
  123. end;
  124. {$ifdef TEMPHEAP}
  125. switch_to_temp_heap;
  126. {$endif TEMPHEAP}
  127. end;
  128. function GetExePath: string;
  129. var Path: string;
  130. I: integer;
  131. begin
  132. Path:='.'+DirSep;
  133. if DirectorySwitches<>nil then
  134. with DirectorySwitches^ do
  135. for I:=0 to ItemCount-1 do
  136. begin
  137. if Pos('EXE',KillTilde(ItemName(I)))>0 then
  138. begin Path:=GetStringItem(I); Break; end;
  139. end;
  140. GetExePath:=CompleteDir(FExpand(Path));
  141. end;
  142. {****************************************************************************
  143. DoCompile
  144. ****************************************************************************}
  145. procedure DoCompile(Mode: TCompileMode);
  146. function IsExitEvent(E: TEvent): boolean;
  147. begin
  148. IsExitEvent:=(E.What=evKeyDown) and
  149. ((E.KeyCode=kbEnter) or (E.KeyCode=kbEsc)) or
  150. ((E.What=evCommand) and (E.command=cmClose));
  151. end;
  152. var
  153. P: PSourceWindow;
  154. FileName: string;
  155. E: TEvent;
  156. { WasVisible: boolean;}
  157. begin
  158. { Get FileName }
  159. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  160. if (PrimaryFile='') and (P=nil) then
  161. begin
  162. ErrorBox('Oooops, nothing to compile.',nil);
  163. Exit;
  164. end;
  165. if PrimaryFile<>'' then
  166. FileName:=PrimaryFile
  167. else
  168. begin
  169. if P^.Editor^.Modified and (not P^.Editor^.Save) then
  170. begin
  171. ErrorBox('Can''t compile unsaved file.',nil);
  172. Exit;
  173. end;
  174. FileName:=P^.Editor^.FileName;
  175. end;
  176. WriteSwitches(SwitchesPath);
  177. MainFile:=FixFileName(FExpand(FileName));
  178. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt);
  179. { Reset }
  180. CtrlBreakHit:=false;
  181. { Show Program Info }
  182. { WasVisible:=ProgramInfoWindow^.GetState(sfVisible);
  183. ProgramInfoWindow^.LogLB^.Clear;
  184. if WasVisible=false then
  185. ProgramInfoWindow^.Show;
  186. ProgramInfoWindow^.MakeFirst;}
  187. CompilationPhase:=cpCompiling;
  188. New(SD, Init);
  189. SD^.SetState(sfModal,true);
  190. Application^.Insert(SD);
  191. SD^.Update;
  192. do_status:=CompilerStatus;
  193. do_stop:=CompilerStop;
  194. do_comment:=CompilerComment;
  195. {$ifdef go32v2}
  196. ChangeRedir('fp$$$.out',false);
  197. ChangeErrorRedir('fp$$$.err',false);
  198. {$endif def go32v2}
  199. {$ifdef TEMPHEAP}
  200. split_heap;
  201. switch_to_temp_heap;
  202. {$endif TEMPHEAP}
  203. Compile(FileName);
  204. {$ifdef TEMPHEAP}
  205. switch_to_base_heap;
  206. {$endif TEMPHEAP}
  207. {$ifdef go32v2}
  208. RestoreRedir;
  209. RestoreErrorRedir;
  210. {$endif def go32v2}
  211. if status.errorCount=0
  212. then CompilationPhase:=cpDone
  213. else CompilationPhase:=cpFailed;
  214. SD^.Update;
  215. SD^.SetState(sfModal,false);
  216. if ((CompilationPhase in[cpDone,cpFailed]) or (ShowStatusOnError)) and (Mode<>cRun) then
  217. repeat
  218. SD^.GetEvent(E);
  219. if IsExitEvent(E)=false then
  220. SD^.HandleEvent(E);
  221. until IsExitEvent(E);
  222. Application^.Delete(SD);
  223. Dispose(SD, Done); SD:=nil;
  224. { if (WasVisible=false) and (status.errorcount=0) then
  225. ProgramInfoWindow^.Hide;}
  226. Message(Application,evCommand,cmUpdate,nil);
  227. {$ifdef TEMPHEAP}
  228. releasetempheap;
  229. unsplit_heap;
  230. {$endif TEMPHEAP}
  231. end;
  232. end.
  233. {
  234. $Log$
  235. Revision 1.11 1999-02-08 09:31:00 florian
  236. + some split heap stuff, in $ifdef TEMPHEAP
  237. Revision 1.10 1999/02/05 13:51:39 peter
  238. * unit name of FPSwitches -> FPSwitch which is easier to use
  239. * some fixes for tp7 compiling
  240. Revision 1.9 1999/02/05 13:06:28 pierre
  241. * allow cmClose for Compilation Dialog box
  242. Revision 1.8 1999/02/04 13:32:01 pierre
  243. * Several things added (I cannot commit them independently !)
  244. + added TBreakpoint and TBreakpointCollection
  245. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  246. + Breakpoint list in INIFile
  247. * Select items now also depend of SwitchMode
  248. * Reading of option '-g' was not possible !
  249. + added search for -Fu args pathes in TryToOpen
  250. + added code for automatic opening of FileDialog
  251. if source not found
  252. Revision 1.7 1999/01/21 11:54:11 peter
  253. + tools menu
  254. + speedsearch in symbolbrowser
  255. * working run command
  256. Revision 1.6 1999/01/15 16:12:43 peter
  257. * fixed crash after compile
  258. Revision 1.5 1999/01/14 21:42:19 peter
  259. * source tracking from Gabor
  260. Revision 1.4 1999/01/12 14:29:32 peter
  261. + Implemented still missing 'switch' entries in Options menu
  262. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  263. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  264. ASCII chars and inserted directly in the text.
  265. + Added symbol browser
  266. * splitted fp.pas to fpide.pas
  267. Revision 1.3 1999/01/04 11:49:42 peter
  268. * 'Use tab characters' now works correctly
  269. + Syntax highlight now acts on File|Save As...
  270. + Added a new class to syntax highlight: 'hex numbers'.
  271. * There was something very wrong with the palette managment. Now fixed.
  272. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  273. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  274. process revised
  275. Revision 1.2 1998/12/28 15:47:42 peter
  276. + Added user screen support, display & window
  277. + Implemented Editor,Mouse Options dialog
  278. + Added location of .INI and .CFG file
  279. + Option (INI) file managment implemented (see bottom of Options Menu)
  280. + Switches updated
  281. + Run program
  282. Revision 1.3 1998/12/22 10:39:40 peter
  283. + options are now written/read
  284. + find and replace routines
  285. }