2
0

fpcompil.pas 35 KB

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