fpcompil.pas 36 KB

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