fpcompil.pas 36 KB

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