fpcompil.pas 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. {$i globdir.inc}
  13. unit FPCompil;
  14. interface
  15. { don't redir under linux, because all stdout (also from the ide!) will
  16. then be redired (PFV) }
  17. { this should work now correctly because
  18. RedirDisableAll and RedirEnableAll function are added in fpredir (PM) }
  19. { $define VERBOSETXT}
  20. {$mode objfpc}
  21. uses
  22. Objects,
  23. {$ifdef COMPILER_1_0}
  24. Files,
  25. {$else COMPILER_1_0}
  26. FInput,
  27. {$endif COMPILER_1_0}
  28. Drivers,Views,Dialogs,
  29. WUtils,WViews,WCEdit,
  30. FPSymbol,
  31. FPViews;
  32. type
  33. TCompileMode = (cBuild,cMake,cCompile,cRun);
  34. type
  35. PCompilerMessage = ^TCompilerMessage;
  36. TCompilerMessage = object(TMessageItem)
  37. function GetText(MaxLen: Sw_Integer): String; virtual;
  38. end;
  39. PCompilerMessageListBox = ^TCompilerMessageListBox;
  40. TCompilerMessageListBox = object(TMessageListBox)
  41. function GetPalette: PPalette; virtual;
  42. procedure SelectFirstError;
  43. end;
  44. PCompilerMessageWindow = ^TCompilerMessageWindow;
  45. TCompilerMessageWindow = object(TFPWindow)
  46. constructor Init;
  47. procedure HandleEvent(var Event: TEvent); virtual;
  48. function GetPalette: PPalette; virtual;
  49. procedure Close;virtual;
  50. destructor Done; virtual;
  51. procedure SizeLimits(var Min, Max: TPoint); virtual;
  52. procedure AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  53. procedure ClearMessages;
  54. constructor Load(var S: TStream);
  55. procedure Store(var S: TStream);
  56. procedure SetState(AState: Word; Enable: Boolean); virtual;
  57. procedure UpdateCommands; virtual;
  58. private
  59. {CompileShowed : boolean;}
  60. {Mode : TCompileMode;}
  61. MsgLB : PCompilerMessageListBox;
  62. {CurrST,
  63. InfoST : PColorStaticText;}
  64. end;
  65. PCompilerStatusDialog = ^TCompilerStatusDialog;
  66. TCompilerStatusDialog = object(TCenterDialog)
  67. ST : PAdvancedStaticText;
  68. KeyST : PColorStaticText;
  69. constructor Init;
  70. destructor Done;virtual;
  71. procedure Update;
  72. end;
  73. {$ifdef COMPILER_1_0}
  74. PFPInputFile = ^TFPInputFile;
  75. TFPInputFile = object(tinputfile)
  76. constructor Init(AEditor: PFileEditor);
  77. {$ifdef FPC}protected{$else}public{$endif}
  78. function fileopen(const filename: string): boolean; virtual;
  79. function fileseek(pos: longint): boolean; virtual;
  80. function fileread(var databuf; maxsize: longint): longint; virtual;
  81. function fileeof: boolean; virtual;
  82. function fileclose: boolean; virtual;
  83. private
  84. Editor: PFileEditor;
  85. S: PStream;
  86. end;
  87. {$else COMPILER_1_0}
  88. TFPInputFile = class(tinputfile)
  89. constructor Create(AEditor: PFileEditor);
  90. {$ifdef FPC}protected{$else}public{$endif}
  91. function fileopen(const filename: string): boolean; override;
  92. function fileseek(pos: longint): boolean; override;
  93. function fileread(var databuf; maxsize: longint): longint; override;
  94. function fileeof: boolean; override;
  95. function fileclose: boolean; override;
  96. private
  97. Editor: PFileEditor;
  98. S: PStream;
  99. end;
  100. {$endif COMPILER_1_0}
  101. const
  102. CompilerMessageWindow : PCompilerMessageWindow = nil;
  103. CompilerStatusDialog : PCompilerStatusDialog = nil;
  104. CompileStamp : longint = 0;
  105. RestartingDebugger : boolean = false;
  106. procedure DoCompile(Mode: TCompileMode);
  107. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  108. procedure ParseUserScreen;
  109. procedure RegisterFPCompile;
  110. const
  111. CompilingHiddenFile : PSourceWindow = nil;
  112. implementation
  113. uses
  114. {$ifdef Unix}
  115. {$ifdef VER1_0}
  116. Linux,
  117. {$else}
  118. Unix,
  119. {$endif}
  120. {$endif}
  121. {$ifdef go32v2}
  122. dpmiexcp,
  123. {$endif}
  124. {$ifdef win32}
  125. signals,
  126. {$endif}
  127. {$ifdef HasSignal}
  128. fpcatch,
  129. {$endif HasSignal}
  130. Dos,
  131. {$ifdef fpc}
  132. Video,
  133. {$endif fpc}
  134. StdDlg,App,tokens,
  135. {$ifdef FVISION}
  136. FVConsts,
  137. {$else}
  138. Commands,
  139. {$endif}
  140. CompHook, Compiler, systems, browcol,
  141. WEditor,
  142. FPString,FPRedir,FPDesk,
  143. FPUsrScr,FPHelp,
  144. {$ifndef NODEBUG}FPDebug,{$endif}
  145. FPConst,FPVars,FPUtils,
  146. FPCodCmp,FPIntf,FPSwitch;
  147. {$ifndef NOOBJREG}
  148. const
  149. RCompilerMessageListBox: TStreamRec = (
  150. ObjType: 1211;
  151. VmtLink: Ofs(TypeOf(TCompilerMessageListBox)^);
  152. Load: @TCompilerMessageListBox.Load;
  153. Store: @TCompilerMessageListBox.Store
  154. );
  155. RCompilerMessageWindow: TStreamRec = (
  156. ObjType: 1212;
  157. VmtLink: Ofs(TypeOf(TCompilerMessageWindow)^);
  158. Load: @TCompilerMessageWindow.Load;
  159. Store: @TCompilerMessageWindow.Store
  160. );
  161. {$endif}
  162. procedure ParseUserScreen;
  163. var
  164. y : longint;
  165. Text,Attr : String;
  166. DisplayCompilerWindow : boolean;
  167. cc: integer;
  168. procedure SearchBackTrace;
  169. var AText,ModuleName,st : String;
  170. row : longint;
  171. begin
  172. if pos(' 0x',Text)=1 then
  173. begin
  174. AText:=Text;
  175. Delete(Text,1,10);
  176. While pos(' ',Text)=1 do
  177. Delete(Text,1,1);
  178. if pos('of ',Text)>0 then
  179. begin
  180. ModuleName:=Copy(Text,pos('of ',Text)+3,255);
  181. While ModuleName[Length(ModuleName)]=' ' do
  182. Delete(ModuleName,Length(ModuleName),1);
  183. end
  184. else
  185. ModuleName:='';
  186. if pos('line ',Text)>0 then
  187. begin
  188. Text:=Copy(Text,Pos('line ',Text)+5,255);
  189. st:=Copy(Text,1,Pos(' ',Text)-1);
  190. Val(st,row,cc);
  191. end
  192. else
  193. row:=0;
  194. CompilerMessageWindow^.AddMessage(V_Fatal,AText
  195. ,ModuleName,row,1);
  196. DisplayCompilerWindow:=true;
  197. end;
  198. end;
  199. procedure InsertInMessages(Const TypeStr : String;_Type : longint;EnableDisplay : boolean);
  200. var p,p2,col,row : longint;
  201. St,ModuleName : string;
  202. begin
  203. p:=pos(TypeStr,Text);
  204. p2:=Pos('(',Text);
  205. if (p>0) and (p2>0) and (p2<p) then
  206. begin
  207. ModuleName:=Copy(Text,1,p2-1);
  208. st:=Copy(Text,p2+1,255);
  209. Val(Copy(st,1,pos(',',st)-1),row,cc);
  210. st:=Copy(st,Pos(',',st)+1,255);
  211. Val(Copy(st,1,pos(')',st)-1),col,cc);
  212. CompilerMessageWindow^.AddMessage(_type,Copy(Text,pos(':',Text)+1,255)
  213. ,ModuleName,row,col);
  214. If EnableDisplay then
  215. DisplayCompilerWindow:=true;
  216. end;
  217. end;
  218. begin
  219. if not assigned(UserScreen) then
  220. exit;
  221. DisplayCompilerWindow:=false;
  222. PushStatus('Parsing User Screen');
  223. CompilerMessageWindow^.Lock;
  224. for Y:=0 to UserScreen^.GetHeight do
  225. begin
  226. UserScreen^.GetLine(Y,Text,Attr);
  227. SearchBackTrace;
  228. InsertInMessages(' Fatal:',v_Fatal,true);
  229. InsertInMessages(' Error:',v_Error,true);
  230. InsertInMessages(' Warning:',v_Warning,false);
  231. InsertInMessages(' Note:',v_Note,false);
  232. InsertInMessages(' Info:',v_Info,false);
  233. InsertInMessages(' Hint:',v_Hint,false);
  234. end;
  235. if DisplayCompilerWindow then
  236. begin
  237. if not CompilerMessageWindow^.GetState(sfVisible) then
  238. CompilerMessageWindow^.Show;
  239. CompilerMessageWindow^.MakeFirst;
  240. CompilerMessageWindow^.MsgLB^.SelectFirstError;
  241. end;
  242. CompilerMessageWindow^.UnLock;
  243. PopStatus;
  244. end;
  245. {*****************************************************************************
  246. TCompilerMessage
  247. *****************************************************************************}
  248. function TCompilerMessage.GetText(MaxLen: Sw_Integer): String;
  249. var
  250. ClassS: string[20];
  251. S: string;
  252. begin
  253. if TClass=
  254. V_Fatal then ClassS:=msg_class_Fatal else if TClass =
  255. V_Error then ClassS:=msg_class_Error else if TClass =
  256. V_Normal then ClassS:=msg_class_Normal else if TClass =
  257. V_Warning then ClassS:=msg_class_Warning else if TClass =
  258. V_Note then ClassS:=msg_class_Note else if TClass =
  259. V_Hint then ClassS:=msg_class_Hint
  260. {$ifdef VERBOSETXT}
  261. else if TClass =
  262. V_Macro then ClassS:=msg_class_macro else if TClass =
  263. V_Procedure then ClassS:=msg_class_procedure else if TClass =
  264. V_Conditional then ClassS:=msg_class_conditional else if TClass =
  265. V_Info then ClassS:=msg_class_info else if TClass =
  266. V_Status then ClassS:=msg_class_status else if TClass =
  267. V_Used then ClassS:=msg_class_used else if TClass =
  268. V_Tried then ClassS:=msg_class_tried else if TClass =
  269. V_Debug then ClassS:=msg_class_debug
  270. else
  271. ClassS:='???';
  272. {$else}
  273. else
  274. ClassS:='';
  275. {$endif}
  276. if ClassS<>'' then
  277. ClassS:=RExpand(ClassS,0)+': ';
  278. if assigned(Module) and
  279. (TClass<=V_ShowFile)
  280. {and (status.currentsource<>'') and (status.currentline>0)} then
  281. begin
  282. if Row>0 then
  283. begin
  284. if Col>0 then
  285. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  286. else
  287. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  288. end
  289. else
  290. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  291. end
  292. else
  293. S:=ClassS;
  294. if assigned(Text) then
  295. S:=S+Text^;
  296. if length(S)>MaxLen then
  297. S:=copy(S,1,MaxLen-2)+'..';
  298. GetText:=S;
  299. end;
  300. {*****************************************************************************
  301. TCompilerMessageListBox
  302. *****************************************************************************}
  303. function TCompilerMessageListBox.GetPalette: PPalette;
  304. const
  305. P: string[length(CBrowserListBox)] = CBrowserListBox;
  306. begin
  307. GetPalette:=@P;
  308. end;
  309. procedure TCompilerMessageListBox.SelectFirstError;
  310. function IsError(P : PCompilerMessage) : boolean;
  311. begin
  312. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  313. end;
  314. var
  315. P : PCompilerMessage;
  316. begin
  317. P:=List^.FirstThat(@IsError);
  318. If Assigned(P) then
  319. Begin
  320. FocusItem(List^.IndexOf(P));
  321. DrawView;
  322. End;
  323. end;
  324. {*****************************************************************************
  325. TCompilerMessageWindow
  326. *****************************************************************************}
  327. constructor TCompilerMessageWindow.Init;
  328. var R: TRect;
  329. HSB,VSB: PScrollBar;
  330. begin
  331. Desktop^.GetExtent(R);
  332. R.A.Y:=R.B.Y-7;
  333. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  334. HelpCtx:=hcCompilerMessagesWindow;
  335. AutoNumber:=true;
  336. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  337. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  338. Insert(HSB);
  339. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  340. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  341. Insert(VSB);
  342. GetExtent(R);
  343. R.Grow(-1,-1);
  344. New(MsgLB, Init(R, HSB, VSB));
  345. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  346. Insert(MsgLB);
  347. CompilerMessageWindow:=@self;
  348. end;
  349. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  350. begin
  351. if AClass>=V_Info then
  352. Line:=0;
  353. MsgLB^.AddItem(New(PCompilerMessage,Init(AClass, Msg, MsgLB^.AddModuleName(Module), Line, Column)));
  354. if (@Self=CompilerMessageWindow) and ((AClass = V_fatal) or (AClass = V_Error)) then
  355. begin
  356. if not GetState(sfVisible) then
  357. Show;
  358. if Desktop^.First<>PView(CompilerMessageWindow) then
  359. MakeFirst;
  360. end;
  361. end;
  362. procedure TCompilerMessageWindow.ClearMessages;
  363. begin
  364. MsgLB^.Clear;
  365. ReDraw;
  366. end;
  367. {procedure TCompilerMessageWindow.Updateinfo;
  368. begin
  369. if CompileShowed then
  370. begin
  371. InfoST^.SetText(
  372. RExpand(' Main file : '#1#$7f+Copy(SmartPath(MainFile),1,39),40)+#2+
  373. 'Total lines : '#1#$7e+IntToStr(Status.CompiledLines)+#2#13+
  374. RExpand(' Target : '#1#$7f+KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),40)+#2+
  375. 'Total errors : '#1#$7e+IntToStr(Status.ErrorCount)
  376. );
  377. if status.currentline>0 then
  378. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+'('+IntToStr(status.currentline)+')'#2)
  379. else
  380. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+#2);
  381. end;
  382. ReDraw;
  383. end;}
  384. procedure TCompilerMessageWindow.HandleEvent(var Event: TEvent);
  385. begin
  386. case Event.What of
  387. evBroadcast :
  388. case Event.Command of
  389. cmListFocusChanged :
  390. if Event.InfoPtr=MsgLB then
  391. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  392. end;
  393. end;
  394. inherited HandleEvent(Event);
  395. end;
  396. procedure TCompilerMessageWindow.SizeLimits(var Min, Max: TPoint);
  397. begin
  398. inherited SizeLimits(Min,Max);
  399. Min.X:=20;
  400. Min.Y:=4;
  401. end;
  402. procedure TCompilerMessageWindow.Close;
  403. begin
  404. Hide;
  405. end;
  406. function TCompilerMessageWindow.GetPalette: PPalette;
  407. const
  408. S : string[length(CBrowserWindow)] = CBrowserWindow;
  409. begin
  410. GetPalette:=@S;
  411. end;
  412. constructor TCompilerMessageWindow.Load(var S: TStream);
  413. begin
  414. inherited Load(S);
  415. GetSubViewPtr(S,MsgLB);
  416. end;
  417. procedure TCompilerMessageWindow.Store(var S: TStream);
  418. begin
  419. if MsgLB^.List=nil then
  420. MsgLB^.NewList(New(PCollection, Init(100,100)));
  421. inherited Store(S);
  422. PutSubViewPtr(S,MsgLB);
  423. end;
  424. procedure TCompilerMessageWindow.UpdateCommands;
  425. var Active: boolean;
  426. begin
  427. Active:=GetState(sfActive);
  428. SetCmdState(CompileCmds,Active);
  429. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  430. end;
  431. procedure TCompilerMessageWindow.SetState(AState: Word; Enable: Boolean);
  432. var OldState: word;
  433. begin
  434. OldState:=State;
  435. inherited SetState(AState,Enable);
  436. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  437. UpdateCommands;
  438. end;
  439. destructor TCompilerMessageWindow.Done;
  440. begin
  441. CompilerMessageWindow:=nil;
  442. inherited Done;
  443. end;
  444. {****************************************************************************
  445. CompilerStatusDialog
  446. ****************************************************************************}
  447. constructor TCompilerStatusDialog.Init;
  448. var R: TRect;
  449. begin
  450. R.Assign(0,0,50,11);
  451. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  452. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  453. GetExtent(R); R.B.Y:=11;
  454. R.Grow(-3,-2);
  455. New(ST, Init(R, ''));
  456. Insert(ST);
  457. GetExtent(R); R.B.Y:=11;
  458. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  459. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256,true));
  460. Insert(KeyST);
  461. { Reset Status infos see bug 1585 }
  462. Fillchar(Status,SizeOf(Status),#0);
  463. end;
  464. destructor TCompilerStatusDialog.Done;
  465. begin
  466. if @Self=CompilerStatusDialog then
  467. CompilerStatusDialog:=nil;
  468. Inherited Done;
  469. end;
  470. procedure TCompilerStatusDialog.Update;
  471. var
  472. StatusS,KeyS: string;
  473. const
  474. MaxFileNameSize = 46;
  475. begin
  476. {$ifdef TEMPHEAP}
  477. switch_to_base_heap;
  478. {$endif TEMPHEAP}
  479. case CompilationPhase of
  480. cpCompiling :
  481. begin
  482. ClearFormatParams;
  483. if Status.Compiling_current then
  484. begin
  485. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  486. MaxFileNameSize - Length(msg_compilingfile)));
  487. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  488. end
  489. else
  490. begin
  491. if Status.CurrentSource='' then
  492. StatusS:=''
  493. else
  494. begin
  495. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  496. MaxFileNameSize-Length(msg_loadingunit));
  497. AddFormatParamStr(StatusS);
  498. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  499. end;
  500. end;
  501. KeyS:=msg_hint_pressesctocancel;
  502. end;
  503. cpLinking :
  504. begin
  505. ClearFormatParams;
  506. AddFormatParamStr(ShrinkPath(ExeFile,
  507. MaxFileNameSize-Length(msg_linkingfile)));
  508. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  509. KeyS:=msg_hint_pleasewait;
  510. end;
  511. cpDone :
  512. begin
  513. StatusS:=msg_compiledone;
  514. KeyS:=msg_hint_compilesuccessfulpressenter;
  515. end;
  516. cpFailed :
  517. begin
  518. StatusS:=msg_failedtocompile;
  519. KeyS:=msg_hint_compilefailed;
  520. end;
  521. cpAborted :
  522. begin
  523. StatusS:=msg_compilationaborted;
  524. KeyS:=msg_hint_compileaborted;
  525. end;
  526. end;
  527. ClearFormatParams;
  528. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  529. MaxFileNameSize-Length('Main file: %s')));
  530. AddFormatParamStr(StatusS);
  531. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  532. AddFormatParamInt(Status.CurrentLine);
  533. AddFormatParamInt(MemAvail div 1024);
  534. AddFormatParamInt(Status.CompiledLines);
  535. AddFormatParamInt(Status.ErrorCount);
  536. ST^.SetText(
  537. FormatStrF(
  538. 'Main file: %s'#13+
  539. '%s'+#13#13+
  540. 'Target: %12s '+ 'Line number: %7d'+#13+
  541. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  542. 'Total errors: %5d',
  543. FormatParams)
  544. );
  545. KeyST^.SetText(^C+KeyS);
  546. {$ifdef TEMPHEAP}
  547. switch_to_temp_heap;
  548. {$endif TEMPHEAP}
  549. end;
  550. {****************************************************************************
  551. Compiler Hooks
  552. ****************************************************************************}
  553. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  554. var
  555. event : tevent;
  556. begin
  557. GetKeyEvent(Event);
  558. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  559. begin
  560. CompilationPhase:=cpAborted;
  561. { update info messages }
  562. if assigned(CompilerStatusDialog) then
  563. begin
  564. {$ifdef redircompiler}
  565. RedirDisableAll;
  566. {$endif}
  567. CompilerStatusDialog^.Update;
  568. {$ifdef redircompiler}
  569. RedirEnableAll;
  570. {$endif}
  571. end;
  572. CompilerStatus:=true;
  573. exit;
  574. end;
  575. { only display line info every 100 lines, ofcourse all other messages
  576. will be displayed directly }
  577. if (status.currentline mod 100=0) then
  578. begin
  579. { update info messages }
  580. {$ifdef redircompiler}
  581. RedirDisableAll;
  582. {$endif}
  583. if assigned(CompilerStatusDialog) then
  584. CompilerStatusDialog^.Update;
  585. {$ifdef redircompiler}
  586. RedirEnableAll;
  587. {$endif}
  588. { update memory usage }
  589. { HeapView^.Update; }
  590. end;
  591. CompilerStatus:=false;
  592. end;
  593. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  594. begin
  595. {$ifndef GABOR}
  596. if StopJmpValid then
  597. Longjmp(StopJmp,1)
  598. else
  599. Halt(1);
  600. {$endif}
  601. end;
  602. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  603. var t: longint;
  604. W: PSourceWindow;
  605. begin
  606. W:=EditorWindowFile(FExpand(filename));
  607. if Assigned(W) and (W^.Editor^.GetModified) then
  608. t:=Now
  609. else
  610. t:=def_getnamedfiletime(filename);
  611. CompilerGetNamedFileTime:=t;
  612. end;
  613. {$ifdef COMPILER_1_0}
  614. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  615. var f: pinputfile;
  616. W: PSourceWindow;
  617. begin
  618. if assigned(CompilingHiddenFile) and
  619. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  620. W:=CompilingHiddenFile
  621. else
  622. W:=EditorWindowFile(FExpand(filename));
  623. if Assigned(W) and (W^.Editor^.GetModified) then
  624. f:=new(PFPInputFile, Init(W^.Editor))
  625. else
  626. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  627. if assigned(W) then
  628. W^.Editor^.CompileStamp:=CompileStamp;
  629. CompilerOpenInputFile:=f;
  630. end;
  631. {$else COMPILER_1_0}
  632. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  633. var f: tinputfile;
  634. W: PSourceWindow;
  635. begin
  636. if assigned(CompilingHiddenFile) and
  637. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  638. W:=CompilingHiddenFile
  639. else
  640. W:=EditorWindowFile(FExpand(filename));
  641. if Assigned(W) and (W^.Editor^.GetModified) then
  642. f:=TFPInputFile.Create(W^.Editor)
  643. else
  644. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  645. if assigned(W) then
  646. W^.Editor^.CompileStamp:=CompileStamp;
  647. CompilerOpenInputFile:=f;
  648. end;
  649. {$endif COMPILER_1_0}
  650. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  651. begin
  652. {$ifdef TEMPHEAP}
  653. switch_to_base_heap;
  654. {$endif TEMPHEAP}
  655. CompilerComment:=false;
  656. {$ifndef DEV}
  657. if (status.verbosity and Level)=Level then
  658. {$endif}
  659. begin
  660. {$ifdef redircompiler}
  661. RedirDisableAll;
  662. {$endif}
  663. if not CompilerMessageWindow^.GetState(sfVisible) then
  664. CompilerMessageWindow^.Show;
  665. if Desktop^.First<>PView(CompilerMessageWindow) then
  666. CompilerMessageWindow^.MakeFirst;
  667. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  668. status.currentline,status.currentcolumn);
  669. { update info messages }
  670. if assigned(CompilerStatusDialog) then
  671. CompilerStatusDialog^.Update;
  672. {$ifdef DEBUG}
  673. {$ifndef NODEBUG}
  674. // def_gdb_stop(level);
  675. {$endif}
  676. {$endif DEBUG}
  677. {$ifdef redircompiler}
  678. RedirEnableAll;
  679. {$endif}
  680. { update memory usage }
  681. { HeapView^.Update; }
  682. end;
  683. {$ifdef TEMPHEAP}
  684. switch_to_temp_heap;
  685. {$endif TEMPHEAP}
  686. end;
  687. {****************************************************************************
  688. DoCompile
  689. ****************************************************************************}
  690. { This function must return '' if
  691. "Options|Directories|Exe and PPU directory" is empty }
  692. function GetExePath: string;
  693. var Path: string;
  694. I: Sw_integer;
  695. begin
  696. Path:='';
  697. if DirectorySwitches<>nil then
  698. with DirectorySwitches^ do
  699. for I:=0 to ItemCount-1 do
  700. begin
  701. if ItemParam(I)='-FE' then
  702. begin
  703. Path:=GetStringItem(I);
  704. Break;
  705. end;
  706. end;
  707. if Path<>'' then
  708. GetExePath:=CompleteDir(FExpand(Path))
  709. else
  710. GetExePath:='';
  711. end;
  712. function GetMainFile(Mode: TCompileMode): string;
  713. var FileName: string;
  714. P : PSourceWindow;
  715. begin
  716. if assigned(CompilingHiddenFile) then
  717. P:=CompilingHiddenFile
  718. else
  719. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  720. if (PrimaryFileMain='') and (P=nil) then
  721. FileName:='' { nothing to compile }
  722. else
  723. begin
  724. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  725. FileName:=PrimaryFileMain
  726. else if assigned(P) then
  727. begin
  728. FileName:=P^.Editor^.FileName;
  729. if FileName='' then
  730. begin
  731. P^.Editor^.SaveAsk(true);
  732. FileName:=P^.Editor^.FileName;
  733. end;
  734. end
  735. else
  736. FileName:='';
  737. end;
  738. If (FileName<>'') then
  739. FileName:=FixFileName(FExpand(FileName));
  740. GetMainFile:=FileName;
  741. end;
  742. procedure ResetErrorMessages;
  743. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  744. begin
  745. if assigned(P) and
  746. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  747. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  748. end;
  749. begin
  750. Desktop^.ForEach(@ResetErrorLine);
  751. end;
  752. procedure DoCompile(Mode: TCompileMode);
  753. function IsExitEvent(E: TEvent): boolean;
  754. begin
  755. { following suggestion by Harsha Senanayake }
  756. IsExitEvent:=(E.What=evKeyDown);
  757. end;
  758. var
  759. s,FileName: string;
  760. ErrFile : Text;
  761. MustRestartDebugger,
  762. StoreStopJumpValid : boolean;
  763. StoreStopJmp : Jmp_buf;
  764. StoreExitProc : pointer;
  765. JmpRet,Error,LinkErrorCount : longint;
  766. E : TEvent;
  767. DummyView: PView;
  768. PPasFile : string[64];
  769. begin
  770. AskRecompileIfModifiedFlag:=true;
  771. { Get FileName }
  772. FileName:=GetMainFile(Mode);
  773. if FileName='' then
  774. begin
  775. ErrorBox(msg_nothingtocompile,nil);
  776. Exit;
  777. end else
  778. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  779. and with the file as primaryfile set it is already incompatible with itself
  780. if FileName='*' then
  781. begin
  782. ErrorBox(msg_cantcompileunsavedfile,nil);
  783. Exit;
  784. end; }
  785. PushStatus('Beginning compilation...');
  786. { Show Compiler Messages Window }
  787. { if not CompilerMessageWindow^.GetState(sfVisible) then
  788. CompilerMessageWindow^.Show;
  789. CompilerMessageWindow^.MakeFirst;}
  790. CompilerMessageWindow^.ClearMessages;
  791. { Tell why we compile }
  792. NeedRecompile(Mode,true);
  793. MainFile:=FileName;
  794. SetStatus('Writing switches to file...');
  795. WriteSwitches(SwitchesPath);
  796. { leaving open browsers leads to crashes !! (PM) }
  797. SetStatus('Preparing symbol info...');
  798. CloseAllBrowsers;
  799. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  800. WriteSymbolsFile(BrowserName);
  801. { MainFile:=FixFileName(FExpand(FileName));}
  802. SetStatus('Preparing to compile...'+NameOf(MainFile));
  803. If GetEXEPath<>'' then
  804. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt)
  805. else
  806. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+ExeExt;
  807. { Reset }
  808. CtrlBreakHit:=false;
  809. { Create Compiler Status Dialog }
  810. CompilationPhase:=cpCompiling;
  811. if not assigned(CompilingHiddenFile) then
  812. begin
  813. New(CompilerStatusDialog, Init);
  814. CompilerStatusDialog^.SetState(sfModal,true);
  815. { disable window closing }
  816. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  817. Application^.Insert(CompilerStatusDialog);
  818. CompilerStatusDialog^.Update;
  819. end;
  820. { hook compiler output }
  821. {$ifdef TP}
  822. do_status:=CompilerStatus;
  823. do_stop:=CompilerStop;
  824. do_comment:=CompilerComment;
  825. {$ifndef GABOR}do_openinputfile:=CompilerOpenInputFile;{$endif}
  826. do_getnamedfiletime:=CompilerGetNamedFileTime;
  827. {$else not TP}
  828. do_status:=@CompilerStatus;
  829. do_stop:=@CompilerStop;
  830. do_comment:=@CompilerComment;
  831. do_openinputfile:=@CompilerOpenInputFile;
  832. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  833. {$endif TP}
  834. do_initsymbolinfo:={$ifdef fpc}@{$endif}InitBrowserCol;
  835. do_donesymbolinfo:={$ifdef fpc}@{$endif}DoneBrowserCol;
  836. do_extractsymbolinfo:={$ifdef fpc}@{$endif}CreateBrowserCol;
  837. { Compile ! }
  838. {$ifdef redircompiler}
  839. ChangeRedirOut(FPOutFileName,false);
  840. ChangeRedirError(FPErrFileName,false);
  841. {$endif}
  842. {$ifdef TEMPHEAP}
  843. split_heap;
  844. switch_to_temp_heap;
  845. {$endif TEMPHEAP}
  846. { insert "" around name so that spaces are allowed }
  847. { only supported in compiler after 2000/01/14 PM }
  848. if pos(' ',FileName)>0 then
  849. FileName:='"'+FileName+'"';
  850. if mode=cBuild then
  851. FileName:='-B '+FileName;
  852. { tokens are created and distroed by compiler.compile !! PM }
  853. DoneTokens;
  854. {$ifdef COMPILER_1_0}
  855. PPasFile:='ppas'+source_os.scriptext;
  856. {$else COMPILER_1_0}
  857. PPasFile:='ppas'+source_info.scriptext;
  858. {$endif COMPILER_1_0}
  859. WUtils.DeleteFile(GetExePath+PpasFile);
  860. SetStatus('Compiling...');
  861. {$ifndef GABOR}
  862. StoreStopJumpValid:=StopJmpValid;
  863. StoreStopJmp:=StopJmp;
  864. StoreExitProc:=ExitProc;
  865. StopJmpValid:=true;
  866. JmpRet:=SetJmp(StopJmp);
  867. if JmpRet=0 then
  868. begin
  869. inc(CompileStamp);
  870. ResetErrorMessages;
  871. {$ifndef NODEBUG}
  872. MustRestartDebugger:=false;
  873. if assigned(Debugger) then
  874. if Debugger^.HasExe then
  875. begin
  876. Debugger^.Reset;
  877. MustRestartDebugger:=true;
  878. end;
  879. {$endif NODEBUG}
  880. FpIntF.Compile(FileName,SwitchesPath);
  881. SetStatus('Finished compiling...');
  882. end
  883. else
  884. begin
  885. { We need to restore Exitproc to the value
  886. it was before calling FPintF.compile PM }
  887. ExitProc:=StoreExitProc;
  888. Inc(status.errorCount);
  889. {$ifdef HasSignal}
  890. Case JmpRet of
  891. SIGINT : s := 'Interrupted by Ctrl-C';
  892. SIGILL : s := 'Illegal instruction';
  893. SIGSEGV : s := 'Signal Segmentation violation';
  894. SIGFPE : s:='Floating point signal';
  895. else
  896. s:='Undetermined signal '+inttostr(JmpRet);
  897. end;
  898. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  899. {$endif HasSignal}
  900. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  901. SetStatus('Long jumped out of compilation...');
  902. end;
  903. StopJmpValid:=StoreStopJumpValid;
  904. StopJmp:=StoreStopJmp;
  905. {$endif}
  906. { tokens are created and distroyed by compiler.compile !! PM }
  907. InitTokens;
  908. if LinkAfter and
  909. ExistsFile(GetExePath+PpasFile) and
  910. (CompilationPhase<>cpAborted) and
  911. (status.errorCount=0) then
  912. begin
  913. CompilationPhase:=cpLinking;
  914. if assigned(CompilerStatusDialog) then
  915. CompilerStatusDialog^.Update;
  916. SetStatus('Assembling and/or linking...');
  917. {$ifndef redircompiler}
  918. { At least here we want to catch output
  919. of batch file PM }
  920. ChangeRedirOut(FPOutFileName,false);
  921. ChangeRedirError(FPErrFileName,false);
  922. {$endif}
  923. {$ifdef Unix}
  924. Shell(GetExePath+PpasFile);
  925. Error:=LinuxError;
  926. {$else}
  927. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  928. Error:=DosError;
  929. {$endif}
  930. SetStatus('Finished linking...');
  931. RestoreRedirOut;
  932. RestoreRedirError;
  933. if Error<>0 then
  934. Inc(status.errorCount);
  935. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  936. begin
  937. Inc(status.errorCount);
  938. ClearFormatParams; AddFormatParamStr(ExeFile);
  939. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  940. {$I-}
  941. Assign(ErrFile,FPErrFileName);
  942. Reset(ErrFile);
  943. if EatIO<>0 then
  944. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  945. else
  946. begin
  947. LinkErrorCount:=0;
  948. While not eof(ErrFile) and (LinkErrorCount<25) do
  949. begin
  950. readln(ErrFile,s);
  951. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  952. inc(LinkErrorCount);
  953. end;
  954. if not eof(ErrFile) then
  955. begin
  956. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  957. CompilerMessageWindow^.AddMessage(V_error,
  958. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  959. end;
  960. Close(ErrFile);
  961. end;
  962. EatIO;
  963. {$I+}
  964. end
  965. else if error=0 then
  966. WUtils.DeleteFile(GetExePath+PpasFile);
  967. end;
  968. {$ifdef TEMPHEAP}
  969. switch_to_base_heap;
  970. {$endif TEMPHEAP}
  971. {$ifdef redircompiler}
  972. RestoreRedirOut;
  973. RestoreRedirError;
  974. {$endif}
  975. PopStatus;
  976. { Set end status }
  977. if not (CompilationPhase in [cpAborted,cpFailed]) then
  978. if (status.errorCount=0) then
  979. begin
  980. CompilationPhase:=cpDone;
  981. LastCompileTime := cardinal(Now);
  982. end
  983. else
  984. CompilationPhase:=cpFailed;
  985. { Show end status }
  986. { reenable window closing }
  987. if assigned(CompilerStatusDialog) then
  988. begin
  989. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  990. CompilerStatusDialog^.Update;
  991. CompilerStatusDialog^.ReDraw;
  992. CompilerStatusDialog^.SetState(sfModal,false);
  993. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  994. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  995. repeat
  996. CompilerStatusDialog^.GetEvent(E);
  997. if IsExitEvent(E)=false then
  998. CompilerStatusDialog^.HandleEvent(E);
  999. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  1000. {if IsExitEvent(E) then
  1001. Application^.PutEvent(E);}
  1002. if assigned(CompilerStatusDialog) then
  1003. begin
  1004. Application^.Delete(CompilerStatusDialog);
  1005. Dispose(CompilerStatusDialog, Done);
  1006. end;
  1007. end;
  1008. CompilerStatusDialog:=nil;
  1009. { end compilation returns true if the messagewindow should be removed }
  1010. if CompilationPhase=cpDone then
  1011. begin
  1012. CompilerMessageWindow^.Hide;
  1013. { This is the last compiled main file }
  1014. PrevMainFile:=MainFile;
  1015. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1016. end;
  1017. { Update the app }
  1018. Message(Application,evCommand,cmUpdate,nil);
  1019. {$ifdef TEMPHEAP}
  1020. releasetempheap;
  1021. unsplit_heap;
  1022. {$endif TEMPHEAP}
  1023. DummyView:=Desktop^.First;
  1024. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1025. begin
  1026. DummyView:=DummyView^.NextView;
  1027. end;
  1028. with DummyView^ do
  1029. if GetState(sfVisible) then
  1030. begin
  1031. SetState(sfSelected,false);
  1032. SetState(sfSelected,true);
  1033. end;
  1034. if Assigned(CompilerMessageWindow) then
  1035. with CompilerMessageWindow^ do
  1036. begin
  1037. if GetState(sfVisible) then
  1038. begin
  1039. SetState(sfSelected,false);
  1040. SetState(sfSelected,true);
  1041. end;
  1042. if (status.errorCount>0) then
  1043. MsgLB^.SelectFirstError;
  1044. end;
  1045. { ^^^ we need this trick to reactivate the desktop }
  1046. EditorModified:=false;
  1047. {$ifndef NODEBUG}
  1048. if MustRestartDebugger then
  1049. InitDebugger;
  1050. {$endif NODEBUG}
  1051. { In case we have something that the compiler touched }
  1052. AskToReloadAllModifiedFiles;
  1053. { Try to read Browser info in again if compilation failure !! }
  1054. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1055. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1056. ReadSymbolsFile(BrowserName);
  1057. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1058. AddAvailableUnitsToCodeComplete(false);
  1059. end;
  1060. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1061. var Need: boolean;
  1062. I: sw_integer;
  1063. SF: PSourceFile;
  1064. SourceTime,PPUTime,ObjTime: longint;
  1065. W: PSourceWindow;
  1066. begin
  1067. if Assigned(SourceFiles)=false then
  1068. Need:={(EditorModified=true)}true
  1069. else
  1070. begin
  1071. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1072. if Need then
  1073. begin
  1074. if verbose then
  1075. begin
  1076. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1077. CompilerMessageWindow^.AddMessage(V_info,
  1078. FormatStrF(msg_firstcompilationof,FormatParams),
  1079. '',0,0);
  1080. end;
  1081. end
  1082. else
  1083. for I:=0 to SourceFiles^.Count-1 do
  1084. begin
  1085. SF:=SourceFiles^.At(I);
  1086. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1087. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1088. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1089. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1090. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1091. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1092. writeln('------');}
  1093. { some units don't generate object files }
  1094. W:=EditorWindowFile(SF^.GetSourceFileName);
  1095. if (SourceTime<>-1) then
  1096. if ((SourceTime>PPUTime) or
  1097. ((SourceTime>ObjTime) and
  1098. (ObjTime<>-1))) or
  1099. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1100. begin
  1101. Need:=true;
  1102. if verbose then
  1103. begin
  1104. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1105. CompilerMessageWindow^.AddMessage(V_info,
  1106. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1107. SF^.GetSourceFileName,1,1);
  1108. end;
  1109. Break;
  1110. end;
  1111. end;
  1112. { writeln('Need?', Need); system.readln;}
  1113. end;
  1114. NeedRecompile:=Need;
  1115. end;
  1116. {$ifdef COMPILER_1_0}
  1117. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1118. begin
  1119. if not Assigned(AEditor) then Fail;
  1120. if inherited Init(AEditor^.FileName)=false then
  1121. Fail;
  1122. Editor:=AEditor;
  1123. end;
  1124. {$else COMPILER_1_0}
  1125. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1126. begin
  1127. if not Assigned(AEditor) then Fail;
  1128. if inherited Create(AEditor^.FileName)=nil then
  1129. Fail;
  1130. Editor:=AEditor;
  1131. end;
  1132. {$endif COMPILER_1_0}
  1133. function TFPInputFile.fileopen(const filename: string): boolean;
  1134. var OK: boolean;
  1135. begin
  1136. S:=New(PMemoryStream, Init(0,0));
  1137. OK:=Assigned(S) and (S^.Status=stOK);
  1138. if OK then OK:=Editor^.SaveToStream(S);
  1139. if OK then
  1140. S^.Seek(0)
  1141. else
  1142. begin
  1143. if Assigned(S) then Dispose(S, Done);
  1144. S:=nil;
  1145. end;
  1146. fileopen:=OK;
  1147. end;
  1148. function TFPInputFile.fileseek(pos: longint): boolean;
  1149. var OK: boolean;
  1150. begin
  1151. OK:=assigned(S);
  1152. if OK then
  1153. begin
  1154. S^.Reset;
  1155. S^.Seek(pos);
  1156. OK:=(S^.Status=stOK);
  1157. end;
  1158. fileseek:=OK;
  1159. end;
  1160. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1161. var
  1162. size: longint;
  1163. begin
  1164. if not assigned(S) then size:=0 else
  1165. begin
  1166. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1167. S^.Read(databuf,size);
  1168. if S^.Status<>stOK then size:=0;
  1169. end;
  1170. fileread:=size;
  1171. end;
  1172. function TFPInputFile.fileeof: boolean;
  1173. var EOF: boolean;
  1174. begin
  1175. EOF:=not assigned(S);
  1176. if not EOF then
  1177. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1178. fileeof:=EOF;
  1179. end;
  1180. function TFPInputFile.fileclose: boolean;
  1181. var OK: boolean;
  1182. begin
  1183. OK:=assigned(S);
  1184. if OK then
  1185. begin
  1186. S^.Reset;
  1187. Dispose(S, Done);
  1188. S:=nil;
  1189. OK:=true;
  1190. end;
  1191. fileclose:=OK;
  1192. end;
  1193. procedure RegisterFPCompile;
  1194. begin
  1195. {$ifndef NOOBJREG}
  1196. RegisterType(RCompilerMessageListBox);
  1197. RegisterType(RCompilerMessageWindow);
  1198. {$endif}
  1199. end;
  1200. end.
  1201. {
  1202. $Log$
  1203. Revision 1.15 2002-09-26 15:00:35 pierre
  1204. * fix problems with system unit is not present for __fp__ compilation
  1205. Revision 1.14 2002/09/13 22:30:50 pierre
  1206. * only fpc uses video unit
  1207. Revision 1.13 2002/09/09 06:53:54 pierre
  1208. * avoid to save file used by codecomplete
  1209. Revision 1.12 2002/09/07 15:40:42 peter
  1210. * old logs removed and tabs fixed
  1211. Revision 1.11 2002/09/05 08:45:40 pierre
  1212. * try to fix recompilation on changes problems
  1213. Revision 1.10 2002/09/04 14:07:12 pierre
  1214. + Enhance code complete by inserting unit symbols
  1215. Revision 1.9 2002/08/26 13:03:14 pierre
  1216. + add a lock to speed up parsing of userscreen
  1217. Revision 1.8 2002/04/10 22:37:37 pierre
  1218. * save and restore Exitproc if LongJmp called
  1219. Revision 1.7 2002/03/20 14:48:27 pierre
  1220. * moved StopJmp buffer to fpcatch unit
  1221. }