fpcompil.pas 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. FPRedir,
  34. FPConst,FPVars,FPUtils,FPIntf,FPSwitch;
  35. constructor TCompileStatusDialog.Init;
  36. var R: TRect;
  37. begin
  38. R.Assign(0,0,50,11+7);
  39. inherited Init(R, 'Compiling');
  40. GetExtent(R); R.B.Y:=11;
  41. R.Grow(-3,-2);
  42. New(ST, Init(R, ''));
  43. Insert(ST);
  44. GetExtent(R); R.B.Y:=11;
  45. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  46. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256));
  47. Insert(KeyST);
  48. GetExtent(R); R.Grow(-1,-1); R.A.Y:=10;
  49. New(MsgLB, Init(R, nil, nil));
  50. Insert(MsgLB);
  51. end;
  52. procedure TCompileStatusDialog.Update;
  53. var StatusS,KeyS: string;
  54. const CtrlBS = 'Press Ctrl+Break to cancel';
  55. SuccessS = 'Compile successful: ~Press Enter~';
  56. FailS = 'Compile failed';
  57. begin
  58. {$ifdef TEMPHEAP}
  59. switch_to_base_heap;
  60. {$endif TEMPHEAP}
  61. case CompilationPhase of
  62. cpCompiling :
  63. begin
  64. StatusS:='Compiling '+Status.CurrentSource;
  65. KeyS:=CtrlBS;
  66. end;
  67. cpLinking :
  68. begin
  69. StatusS:='Linking...';
  70. KeyS:=CtrlBS;
  71. end;
  72. cpDone :
  73. begin
  74. StatusS:='Done.';
  75. KeyS:=SuccessS;
  76. end;
  77. cpFailed :
  78. begin
  79. StatusS:='Failed to compile...';
  80. KeyS:=FailS;
  81. end;
  82. end;
  83. ST^.SetText(
  84. 'Main file: '+SmartPath(MainFile)+#13+
  85. StatusS+#13#13+
  86. 'Target: '+LExpand(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),12)+' '+
  87. 'Line number: '+IntToStrL(Status.CurrentLine,7)+#13+
  88. 'Free memory: '+IntToStrL(MemAvail div 1024,6)+'K'+ ' '+
  89. 'Total lines: '+IntToStrL(Status.CompiledLines,7)+#13+
  90. 'Total errors: '+IntToStrL(Status.ErrorCount,5)
  91. );
  92. KeyST^.SetText(^C+KeyS);
  93. {$ifdef TEMPHEAP}
  94. switch_to_temp_heap;
  95. {$endif TEMPHEAP}
  96. end;
  97. {****************************************************************************
  98. Compiler Hooks
  99. ****************************************************************************}
  100. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  101. begin
  102. if SD<>nil then SD^.Update;
  103. CompilerStatus:=false;
  104. end;
  105. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  106. begin
  107. end;
  108. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  109. begin
  110. {$ifdef TEMPHEAP}
  111. switch_to_base_heap;
  112. {$endif TEMPHEAP}
  113. CompilerComment:=false;
  114. {$ifndef DEV}
  115. if (status.verbosity and Level)=Level then
  116. {$endif}
  117. begin
  118. ProgramInfoWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  119. status.currentline,status.currentcolumn);
  120. if SD<>nil then
  121. SD^.MsgLB^.AddItem(New(PCompilerMessage, Init(Level, S, SmartPath(status.currentmodule),
  122. status.currentline,status.currentcolumn)));
  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. if Assigned(ProgramInfoWindow) then
  188. ProgramInfoWindow^.ClearMessages;
  189. CompilationPhase:=cpCompiling;
  190. New(SD, Init);
  191. SD^.SetState(sfModal,true);
  192. Application^.Insert(SD);
  193. SD^.Update;
  194. do_status:=CompilerStatus;
  195. do_stop:=CompilerStop;
  196. do_comment:=CompilerComment;
  197. {$ifndef debug}
  198. { this avoids all flickers
  199. and allows to get assembler and linker messages
  200. but also forbids to use GDB inside !! }
  201. ChangeRedir('fp$$$.out',false);
  202. ChangeErrorRedir('fp$$$.err',false);
  203. {$endif ndef debug}
  204. {$ifdef TEMPHEAP}
  205. split_heap;
  206. switch_to_temp_heap;
  207. {$endif TEMPHEAP}
  208. Compile(FileName);
  209. {$ifdef TEMPHEAP}
  210. switch_to_base_heap;
  211. {$endif TEMPHEAP}
  212. RestoreRedir;
  213. RestoreErrorRedir;
  214. if status.errorCount=0
  215. then CompilationPhase:=cpDone
  216. else CompilationPhase:=cpFailed;
  217. SD^.Update;
  218. SD^.SetState(sfModal,false);
  219. if ((CompilationPhase in[cpDone,cpFailed]) or (ShowStatusOnError)) and (Mode<>cRun) then
  220. repeat
  221. SD^.GetEvent(E);
  222. if IsExitEvent(E)=false then
  223. SD^.HandleEvent(E);
  224. until IsExitEvent(E);
  225. Application^.Delete(SD);
  226. Dispose(SD, Done); SD:=nil;
  227. { if (WasVisible=false) and (status.errorcount=0) then
  228. ProgramInfoWindow^.Hide;}
  229. Message(Application,evCommand,cmUpdate,nil);
  230. {$ifdef TEMPHEAP}
  231. releasetempheap;
  232. unsplit_heap;
  233. {$endif TEMPHEAP}
  234. end;
  235. end.
  236. {
  237. $Log$
  238. Revision 1.14 1999-02-22 12:46:56 peter
  239. * small fixes for linux and grep
  240. Revision 1.13 1999/02/22 11:51:33 peter
  241. * browser updates from gabor
  242. Revision 1.12 1999/02/22 11:29:36 pierre
  243. + added col info in MessageItem
  244. + grep uses HighLightExts and should work for linux
  245. Revision 1.11 1999/02/08 09:31:00 florian
  246. + some split heap stuff, in $ifdef TEMPHEAP
  247. Revision 1.10 1999/02/05 13:51:39 peter
  248. * unit name of FPSwitches -> FPSwitch which is easier to use
  249. * some fixes for tp7 compiling
  250. Revision 1.9 1999/02/05 13:06:28 pierre
  251. * allow cmClose for Compilation Dialog box
  252. Revision 1.8 1999/02/04 13:32:01 pierre
  253. * Several things added (I cannot commit them independently !)
  254. + added TBreakpoint and TBreakpointCollection
  255. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  256. + Breakpoint list in INIFile
  257. * Select items now also depend of SwitchMode
  258. * Reading of option '-g' was not possible !
  259. + added search for -Fu args pathes in TryToOpen
  260. + added code for automatic opening of FileDialog
  261. if source not found
  262. Revision 1.7 1999/01/21 11:54:11 peter
  263. + tools menu
  264. + speedsearch in symbolbrowser
  265. * working run command
  266. Revision 1.6 1999/01/15 16:12:43 peter
  267. * fixed crash after compile
  268. Revision 1.5 1999/01/14 21:42:19 peter
  269. * source tracking from Gabor
  270. Revision 1.4 1999/01/12 14:29:32 peter
  271. + Implemented still missing 'switch' entries in Options menu
  272. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  273. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  274. ASCII chars and inserted directly in the text.
  275. + Added symbol browser
  276. * splitted fp.pas to fpide.pas
  277. Revision 1.3 1999/01/04 11:49:42 peter
  278. * 'Use tab characters' now works correctly
  279. + Syntax highlight now acts on File|Save As...
  280. + Added a new class to syntax highlight: 'hex numbers'.
  281. * There was something very wrong with the palette managment. Now fixed.
  282. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  283. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  284. process revised
  285. Revision 1.2 1998/12/28 15:47:42 peter
  286. + Added user screen support, display & window
  287. + Implemented Editor,Mouse Options dialog
  288. + Added location of .INI and .CFG file
  289. + Option (INI) file managment implemented (see bottom of Options Menu)
  290. + Switches updated
  291. + Run program
  292. Revision 1.3 1998/12/22 10:39:40 peter
  293. + options are now written/read
  294. + find and replace routines
  295. }