fpcompil.pas 37 KB

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