fpcompil.pas 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. starttime : real;
  73. constructor Init;
  74. destructor Done;virtual;
  75. procedure Update;
  76. procedure SetStartTime(r : real);
  77. end;
  78. TFPInputFile = class(tinputfile)
  79. constructor Create(AEditor: PFileEditor);
  80. protected
  81. function fileopen(const filename: string): boolean; override;
  82. function fileseek(pos: longint): boolean; override;
  83. function fileread(var databuf; maxsize: longint): longint; override;
  84. function fileeof: boolean; override;
  85. function fileclose: boolean; override;
  86. procedure filegettime; override;
  87. private
  88. Editor: PFileEditor;
  89. S: PStream;
  90. end;
  91. const
  92. CompilerMessageWindow : PCompilerMessageWindow = nil;
  93. CompilerStatusDialog : PCompilerStatusDialog = nil;
  94. CompileStamp : longint = 0;
  95. RestartingDebugger : boolean = false;
  96. procedure DoCompile(Mode: TCompileMode);
  97. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  98. procedure ParseUserScreen;
  99. procedure RegisterFPCompile;
  100. const
  101. CompilingHiddenFile : PSourceWindow = nil;
  102. implementation
  103. uses
  104. {$ifdef Unix}
  105. Unix, BaseUnix,
  106. {$endif}
  107. {$ifdef go32v2}
  108. dpmiexcp,
  109. {$endif}
  110. {$ifdef Windows}
  111. {$ifdef HasSignal}
  112. signals,
  113. {$endif}
  114. {$endif}
  115. { $ifdef HasSignal}
  116. fpcatch,
  117. { $endif HasSignal}
  118. Dos,
  119. Video,
  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. function getrealtime : real;
  483. var
  484. {$IFDEF USE_SYSUTILS}
  485. h,m,s,s1000 : word;
  486. {$ELSE USE_SYSUTILS}
  487. h,m,s,s100 : word;
  488. {$ENDIF USE_SYSUTILS}
  489. begin
  490. {$IFDEF USE_SYSUTILS}
  491. DecodeTime(Time,h,m,s,s1000);
  492. getrealtime:=h*3600.0+m*60.0+s+s1000/1000.0;
  493. {$ELSE USE_SYSUTILS}
  494. gettime(h,m,s,s100);
  495. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  496. {$ENDIF USE_SYSUTILS}
  497. end;
  498. constructor TCompilerStatusDialog.Init;
  499. var R: TRect;
  500. begin
  501. R.Assign(0,0,56,11);
  502. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  503. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  504. starttime:=getrealtime;
  505. GetExtent(R); R.B.Y:=11;
  506. R.Grow(-3,-2);
  507. New(ST, Init(R, ''));
  508. Insert(ST);
  509. GetExtent(R); R.B.Y:=11;
  510. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  511. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256,true));
  512. Insert(KeyST);
  513. { Reset Status infos see bug 1585 }
  514. Fillchar(Status,SizeOf(Status),#0);
  515. end;
  516. destructor TCompilerStatusDialog.Done;
  517. begin
  518. if @Self=CompilerStatusDialog then
  519. CompilerStatusDialog:=nil;
  520. Inherited Done;
  521. end;
  522. procedure TCompilerStatusDialog.SetStartTime(r : real);
  523. begin
  524. starttime:=r;
  525. end;
  526. procedure TCompilerStatusDialog.Update;
  527. var
  528. StatusS,KeyS: string;
  529. hstatus : TFPCHeapStatus;
  530. r : real;
  531. const
  532. MaxFileNameSize = 46;
  533. begin
  534. case CompilationPhase of
  535. cpCompiling :
  536. begin
  537. ClearFormatParams;
  538. if Upcase(Status.currentmodulestate)='COMPILE' then
  539. begin
  540. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  541. MaxFileNameSize - Length(msg_compilingfile)));
  542. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  543. end
  544. else
  545. begin
  546. if Status.CurrentSource='' then
  547. StatusS:=''
  548. else
  549. begin
  550. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  551. MaxFileNameSize-Length(msg_loadingunit));
  552. AddFormatParamStr(StatusS);
  553. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  554. end;
  555. end;
  556. KeyS:=msg_hint_pressesctocancel;
  557. end;
  558. cpLinking :
  559. begin
  560. ClearFormatParams;
  561. AddFormatParamStr(ShrinkPath(ExeFile,
  562. MaxFileNameSize-Length(msg_linkingfile)));
  563. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  564. KeyS:=msg_hint_pleasewait;
  565. end;
  566. cpDone :
  567. begin
  568. StatusS:=msg_compiledone;
  569. KeyS:=msg_hint_compilesuccessfulpressenter;
  570. end;
  571. cpFailed :
  572. begin
  573. StatusS:=msg_failedtocompile;
  574. KeyS:=msg_hint_compilefailed;
  575. end;
  576. cpAborted :
  577. begin
  578. StatusS:=msg_compilationaborted;
  579. KeyS:=msg_hint_compileaborted;
  580. end;
  581. end;
  582. ClearFormatParams;
  583. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  584. MaxFileNameSize-Length('Main file: %s')));
  585. AddFormatParamStr(StatusS);
  586. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  587. AddFormatParamInt(Status.CurrentLine);
  588. AddFormatParamInt(Status.CompiledLines);
  589. hstatus:=GetFPCHeapStatus;
  590. AddFormatParamInt(hstatus.CurrHeapUsed div 1024);
  591. AddFormatParamInt(hstatus.CurrHeapSize div 1024);
  592. AddFormatParamInt(Status.ErrorCount);
  593. r:=getrealtime;
  594. AddFormatParamInt(trunc(r-starttime));
  595. AddFormatParamInt(trunc(frac(r-starttime)*10));
  596. ST^.SetText(
  597. FormatStrF(
  598. 'Main file: %s'#13+
  599. '%s'+#13#13+
  600. 'Target: %s'#13+
  601. 'Line number: %6d '+'Total lines: %6d'+#13+
  602. 'Used memory: %6dK '+'Allocated memory: %6dK'#13+
  603. 'Total errors:%6d '+'Compile time: %8d.%1ds',
  604. FormatParams)
  605. );
  606. KeyST^.SetText(^C+KeyS);
  607. end;
  608. {****************************************************************************
  609. Compiler Hooks
  610. ****************************************************************************}
  611. const
  612. lasttime : real = 0;
  613. function CompilerStatus: boolean;
  614. var
  615. event : tevent;
  616. begin
  617. GetKeyEvent(Event);
  618. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  619. begin
  620. CompilationPhase:=cpAborted;
  621. { update info messages }
  622. if assigned(CompilerStatusDialog) then
  623. begin
  624. {$ifdef redircompiler}
  625. RedirDisableAll;
  626. {$endif}
  627. CompilerStatusDialog^.Update;
  628. {$ifdef redircompiler}
  629. RedirEnableAll;
  630. {$endif}
  631. end;
  632. CompilerStatus:=true;
  633. exit;
  634. end;
  635. { only display line info every 100 lines, ofcourse all other messages
  636. will be displayed directly }
  637. if (getrealtime-lasttime>=CompilerStatusUpdateDelay) or (status.compiledlines=1) then
  638. begin
  639. lasttime:=getrealtime;
  640. { update info messages }
  641. {$ifdef redircompiler}
  642. RedirDisableAll;
  643. {$endif}
  644. if assigned(CompilerStatusDialog) then
  645. CompilerStatusDialog^.Update;
  646. {$ifdef redircompiler}
  647. RedirEnableAll;
  648. {$endif}
  649. { update memory usage }
  650. { HeapView^.Update; }
  651. end;
  652. CompilerStatus:=false;
  653. end;
  654. Function CompilerGetNamedFileTime(const filename : string) : Longint;
  655. var t: longint;
  656. W: PSourceWindow;
  657. begin
  658. W:=EditorWindowFile(FExpand(filename));
  659. if Assigned(W) and (W^.Editor^.GetModified) then
  660. t:=Now
  661. else
  662. t:=def_getnamedfiletime(filename);
  663. CompilerGetNamedFileTime:=t;
  664. end;
  665. function CompilerOpenInputFile(const filename: string): tinputfile;
  666. var f: tinputfile;
  667. W: PSourceWindow;
  668. begin
  669. if assigned(CompilingHiddenFile) and
  670. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  671. W:=CompilingHiddenFile
  672. else
  673. W:=EditorWindowFile(FExpand(filename));
  674. if Assigned(W) and (W^.Editor^.GetModified) then
  675. f:=TFPInputFile.Create(W^.Editor)
  676. else
  677. f:=def_openinputfile(filename);
  678. if assigned(W) then
  679. W^.Editor^.CompileStamp:=CompileStamp;
  680. CompilerOpenInputFile:=f;
  681. end;
  682. function CompilerComment(Level:Longint; const s:ansistring):boolean;
  683. begin
  684. CompilerComment:=false;
  685. if (status.verbosity and Level)<>0 then
  686. begin
  687. {$ifdef redircompiler}
  688. RedirDisableAll;
  689. {$endif}
  690. if not CompilerMessageWindow^.GetState(sfVisible) then
  691. CompilerMessageWindow^.Show;
  692. if Desktop^.First<>PView(CompilerMessageWindow) then
  693. CompilerMessageWindow^.MakeFirst;
  694. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  695. status.currentline,status.currentcolumn);
  696. { update info messages }
  697. if assigned(CompilerStatusDialog) then
  698. CompilerStatusDialog^.Update;
  699. {$ifdef redircompiler}
  700. RedirEnableAll;
  701. {$endif}
  702. { update memory usage }
  703. { HeapView^.Update; }
  704. end;
  705. end;
  706. {****************************************************************************
  707. DoCompile
  708. ****************************************************************************}
  709. { This function must return '' if
  710. "Options|Directories|Exe and PPU directory" is empty }
  711. function GetExePath: string;
  712. var Path: string;
  713. I: Sw_integer;
  714. begin
  715. Path:='';
  716. if DirectorySwitches<>nil then
  717. with DirectorySwitches^ do
  718. for I:=0 to ItemCount-1 do
  719. begin
  720. if ItemParam(I)='-FE' then
  721. begin
  722. Path:=GetStringItem(I);
  723. Break;
  724. end;
  725. end;
  726. if Path<>'' then
  727. GetExePath:=CompleteDir(FExpand(Path))
  728. else
  729. GetExePath:='';
  730. end;
  731. function GetMainFile(Mode: TCompileMode): string;
  732. var FileName: string;
  733. P : PSourceWindow;
  734. begin
  735. if assigned(CompilingHiddenFile) then
  736. P:=CompilingHiddenFile
  737. else
  738. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  739. if (PrimaryFileMain='') and (P=nil) then
  740. FileName:='' { nothing to compile }
  741. else
  742. begin
  743. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  744. FileName:=PrimaryFileMain
  745. else if assigned(P) then
  746. begin
  747. FileName:=P^.Editor^.FileName;
  748. if FileName='' then
  749. begin
  750. P^.Editor^.SaveAsk(true);
  751. FileName:=P^.Editor^.FileName;
  752. end;
  753. end
  754. else
  755. FileName:='';
  756. end;
  757. If (FileName<>'') then
  758. FileName:=FixFileName(FExpand(FileName));
  759. GetMainFile:=FileName;
  760. end;
  761. procedure ResetErrorMessages;
  762. procedure ResetErrorLine(P: PView);
  763. begin
  764. if assigned(P) and
  765. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  766. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  767. end;
  768. begin
  769. Desktop^.ForEach(@ResetErrorLine);
  770. end;
  771. procedure DoCompile(Mode: TCompileMode);
  772. function IsExitEvent(E: TEvent): boolean;
  773. begin
  774. { following suggestion by Harsha Senanayake }
  775. IsExitEvent:=(E.What=evKeyDown);
  776. end;
  777. function GetTargetExeExt : string;
  778. begin
  779. GetTargetExeExt:=target_info.exeext;
  780. end;
  781. var
  782. s,FileName: string;
  783. ErrFile : Text;
  784. MustRestartDebugger : boolean;
  785. Error,LinkErrorCount : longint;
  786. E : TEvent;
  787. DummyView: PView;
  788. PPasFile : string[64];
  789. begin
  790. AskRecompileIfModifiedFlag:=true;
  791. { Get FileName }
  792. FileName:=GetMainFile(Mode);
  793. if FileName='' then
  794. begin
  795. ErrorBox(msg_nothingtocompile,nil);
  796. Exit;
  797. end else
  798. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  799. and with the file as primaryfile set it is already incompatible with itself
  800. if FileName='*' then
  801. begin
  802. ErrorBox(msg_cantcompileunsavedfile,nil);
  803. Exit;
  804. end; }
  805. PushStatus('Beginning compilation...');
  806. { Show Compiler Messages Window }
  807. { if not CompilerMessageWindow^.GetState(sfVisible) then
  808. CompilerMessageWindow^.Show;
  809. CompilerMessageWindow^.MakeFirst;}
  810. CompilerMessageWindow^.ClearMessages;
  811. { Tell why we compile }
  812. NeedRecompile(Mode,true);
  813. MainFile:=FileName;
  814. SetStatus('Writing switches to file...');
  815. WriteSwitches(SwitchesPath);
  816. { leaving open browsers leads to crashes !! (PM) }
  817. SetStatus('Preparing symbol info...');
  818. CloseAllBrowsers;
  819. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  820. WriteSymbolsFile(BrowserName);
  821. { MainFile:=FixFileName(FExpand(FileName));}
  822. SetStatus('Preparing to compile...'+NameOf(MainFile));
  823. { Reset }
  824. CtrlBreakHit:=false;
  825. { Create Compiler Status Dialog }
  826. CompilationPhase:=cpCompiling;
  827. if not assigned(CompilingHiddenFile) then
  828. begin
  829. New(CompilerStatusDialog, Init);
  830. CompilerStatusDialog^.SetStartTime(getrealtime);
  831. CompilerStatusDialog^.SetState(sfModal,true);
  832. { disable window closing }
  833. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  834. Application^.Insert(CompilerStatusDialog);
  835. CompilerStatusDialog^.Update;
  836. end;
  837. { Restore dir that could be changed during debugging }
  838. {$I-}
  839. ChDir(StartUpDir);
  840. {$I+}
  841. EatIO;
  842. { hook compiler output }
  843. do_status:=@CompilerStatus;
  844. do_comment:=@CompilerComment;
  845. do_openinputfile:=@CompilerOpenInputFile;
  846. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  847. do_initsymbolinfo:=@InitBrowserCol;
  848. do_donesymbolinfo:=@DoneBrowserCol;
  849. do_extractsymbolinfo:=@CreateBrowserCol;
  850. { Compile ! }
  851. {$ifdef redircompiler}
  852. ChangeRedirOut(FPOutFileName,false);
  853. ChangeRedirError(FPErrFileName,false);
  854. {$endif}
  855. { insert "" around name so that spaces are allowed }
  856. { only supported in compiler after 2000/01/14 PM }
  857. if pos(' ',FileName)>0 then
  858. FileName:='"'+FileName+'"';
  859. if mode=cBuild then
  860. FileName:='-B '+FileName;
  861. { tokens are created and distroed by compiler.compile !! PM }
  862. DoneTokens;
  863. PPasFile:='ppas'+source_info.scriptext;
  864. WUtils.DeleteFile(GetExePath+PpasFile);
  865. SetStatus('Compiling...');
  866. inc(CompileStamp);
  867. ResetErrorMessages;
  868. {$ifndef NODEBUG}
  869. MustRestartDebugger:=false;
  870. if assigned(Debugger) then
  871. if Debugger^.HasExe then
  872. begin
  873. Debugger^.Reset;
  874. MustRestartDebugger:=true;
  875. end;
  876. {$endif NODEBUG}
  877. try
  878. FpIntF.Compile(FileName,SwitchesPath);
  879. except
  880. on ECompilerAbort do
  881. CompilerMessageWindow^.AddMessage(V_error,'Error during compilation','',0,0);
  882. on E:Exception do
  883. CompilerMessageWindow^.AddMessage(V_error,E.Message+' during compilation','',0,0);
  884. end;
  885. SetStatus('Finished compiling...');
  886. { Retrieve created exefile }
  887. If GetEXEPath<>'' then
  888. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+GetTargetExeExt)
  889. else
  890. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+GetTargetExeExt;
  891. DefaultReplacements(ExeFile);
  892. { tokens are created and distroyed by compiler.compile !! PM }
  893. InitTokens;
  894. if LinkAfter and
  895. ExistsFile(GetExePath+PpasFile) and
  896. (CompilationPhase<>cpAborted) and
  897. (status.errorCount=0) then
  898. begin
  899. CompilationPhase:=cpLinking;
  900. if assigned(CompilerStatusDialog) then
  901. CompilerStatusDialog^.Update;
  902. SetStatus('Assembling and/or linking...');
  903. {$ifndef redircompiler}
  904. { At least here we want to catch output
  905. of batch file PM }
  906. ChangeRedirOut(FPOutFileName,false);
  907. ChangeRedirError(FPErrFileName,false);
  908. {$endif}
  909. {$ifdef Unix}
  910. error:=0;
  911. If Shell(GetExePath+PpasFile)=-1 Then
  912. Error:=fpgeterrno;
  913. {$else}
  914. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  915. Error:=DosError;
  916. {$endif}
  917. SetStatus('Finished linking...');
  918. RestoreRedirOut;
  919. RestoreRedirError;
  920. if Error<>0 then
  921. Inc(status.errorCount);
  922. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  923. begin
  924. Inc(status.errorCount);
  925. ClearFormatParams; AddFormatParamStr(ExeFile);
  926. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  927. {$I-}
  928. Assign(ErrFile,FPErrFileName);
  929. Reset(ErrFile);
  930. if EatIO<>0 then
  931. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  932. else
  933. begin
  934. LinkErrorCount:=0;
  935. While not eof(ErrFile) and (LinkErrorCount<25) do
  936. begin
  937. readln(ErrFile,s);
  938. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  939. inc(LinkErrorCount);
  940. end;
  941. if not eof(ErrFile) then
  942. begin
  943. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  944. CompilerMessageWindow^.AddMessage(V_error,
  945. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  946. end;
  947. Close(ErrFile);
  948. end;
  949. EatIO;
  950. {$I+}
  951. end
  952. else if error=0 then
  953. WUtils.DeleteFile(GetExePath+PpasFile);
  954. end;
  955. {$ifdef redircompiler}
  956. RestoreRedirOut;
  957. RestoreRedirError;
  958. {$endif}
  959. PopStatus;
  960. { Set end status }
  961. if not (CompilationPhase in [cpAborted,cpFailed]) then
  962. if (status.errorCount=0) then
  963. begin
  964. CompilationPhase:=cpDone;
  965. LastCompileTime := cardinal(Now);
  966. end
  967. else
  968. CompilationPhase:=cpFailed;
  969. { Show end status }
  970. { reenable window closing }
  971. if assigned(CompilerStatusDialog) then
  972. begin
  973. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  974. CompilerStatusDialog^.Update;
  975. CompilerStatusDialog^.ReDraw;
  976. CompilerStatusDialog^.SetState(sfModal,false);
  977. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  978. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  979. repeat
  980. CompilerStatusDialog^.GetEvent(E);
  981. if IsExitEvent(E)=false then
  982. CompilerStatusDialog^.HandleEvent(E);
  983. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  984. {if IsExitEvent(E) then
  985. Application^.PutEvent(E);}
  986. if assigned(CompilerStatusDialog) then
  987. begin
  988. Application^.Delete(CompilerStatusDialog);
  989. Dispose(CompilerStatusDialog, Done);
  990. end;
  991. end;
  992. CompilerStatusDialog:=nil;
  993. { end compilation returns true if the messagewindow should be removed }
  994. if CompilationPhase=cpDone then
  995. begin
  996. CompilerMessageWindow^.Hide;
  997. { This is the last compiled main file }
  998. PrevMainFile:=MainFile;
  999. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1000. end;
  1001. { Update the app }
  1002. Message(Application,evCommand,cmUpdate,nil);
  1003. DummyView:=Desktop^.First;
  1004. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1005. begin
  1006. DummyView:=DummyView^.NextView;
  1007. end;
  1008. with DummyView^ do
  1009. if GetState(sfVisible) then
  1010. begin
  1011. SetState(sfSelected,false);
  1012. SetState(sfSelected,true);
  1013. end;
  1014. if Assigned(CompilerMessageWindow) then
  1015. with CompilerMessageWindow^ do
  1016. begin
  1017. if GetState(sfVisible) then
  1018. begin
  1019. SetState(sfSelected,false);
  1020. SetState(sfSelected,true);
  1021. end;
  1022. if (status.errorCount>0) then
  1023. MsgLB^.SelectFirstError;
  1024. end;
  1025. { ^^^ we need this trick to reactivate the desktop }
  1026. EditorModified:=false;
  1027. {$ifndef NODEBUG}
  1028. if MustRestartDebugger then
  1029. InitDebugger;
  1030. {$endif NODEBUG}
  1031. { In case we have something that the compiler touched }
  1032. AskToReloadAllModifiedFiles;
  1033. { Try to read Browser info in again if compilation failure !! }
  1034. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1035. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1036. ReadSymbolsFile(BrowserName);
  1037. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1038. AddAvailableUnitsToCodeComplete(false);
  1039. end;
  1040. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1041. var Need: boolean;
  1042. I: sw_integer;
  1043. SF: PSourceFile;
  1044. SourceTime,PPUTime,ObjTime: longint;
  1045. W: PSourceWindow;
  1046. begin
  1047. if Assigned(SourceFiles)=false then
  1048. Need:={(EditorModified=true)}true
  1049. else
  1050. begin
  1051. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1052. if Need then
  1053. begin
  1054. if verbose then
  1055. begin
  1056. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1057. CompilerMessageWindow^.AddMessage(V_info,
  1058. FormatStrF(msg_firstcompilationof,FormatParams),
  1059. '',0,0);
  1060. end;
  1061. end
  1062. else
  1063. for I:=0 to SourceFiles^.Count-1 do
  1064. begin
  1065. SF:=SourceFiles^.At(I);
  1066. SourceTime:=wutils.GetFileTime(SF^.GetSourceFileName);
  1067. PPUTime:=wutils.GetFileTime(SF^.GetPPUFileName);
  1068. ObjTime:=wutils.GetFileTime(SF^.GetObjFileName);
  1069. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1070. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1071. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1072. writeln('------');}
  1073. { some units don't generate object files }
  1074. W:=EditorWindowFile(SF^.GetSourceFileName);
  1075. if (SourceTime<>-1) then
  1076. if ((SourceTime>PPUTime) or
  1077. ((SourceTime>ObjTime) and
  1078. (ObjTime<>-1))) or
  1079. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1080. begin
  1081. Need:=true;
  1082. if verbose then
  1083. begin
  1084. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1085. CompilerMessageWindow^.AddMessage(V_info,
  1086. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1087. SF^.GetSourceFileName,1,1);
  1088. end;
  1089. Break;
  1090. end;
  1091. end;
  1092. { writeln('Need?', Need); system.readln;}
  1093. end;
  1094. NeedRecompile:=Need;
  1095. end;
  1096. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1097. begin
  1098. if not Assigned(AEditor) then Fail;
  1099. if inherited Create(AEditor^.FileName)=nil then
  1100. Fail;
  1101. Editor:=AEditor;
  1102. end;
  1103. function TFPInputFile.fileopen(const filename: string): boolean;
  1104. var OK: boolean;
  1105. begin
  1106. S:=New(PMemoryStream, Init(0,0));
  1107. OK:=Assigned(S) and (S^.Status=stOK);
  1108. if OK then OK:=Editor^.SaveToStream(S);
  1109. if OK then
  1110. S^.Seek(0)
  1111. else
  1112. begin
  1113. if Assigned(S) then Dispose(S, Done);
  1114. S:=nil;
  1115. end;
  1116. fileopen:=OK;
  1117. end;
  1118. function TFPInputFile.fileseek(pos: longint): boolean;
  1119. var OK: boolean;
  1120. begin
  1121. OK:=assigned(S);
  1122. if OK then
  1123. begin
  1124. S^.Reset;
  1125. S^.Seek(pos);
  1126. OK:=(S^.Status=stOK);
  1127. end;
  1128. fileseek:=OK;
  1129. end;
  1130. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1131. var
  1132. size: longint;
  1133. begin
  1134. if not assigned(S) then size:=0 else
  1135. begin
  1136. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1137. S^.Read(databuf,size);
  1138. if S^.Status<>stOK then size:=0;
  1139. end;
  1140. fileread:=size;
  1141. end;
  1142. function TFPInputFile.fileeof: boolean;
  1143. var EOF: boolean;
  1144. begin
  1145. EOF:=not assigned(S);
  1146. if not EOF then
  1147. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1148. fileeof:=EOF;
  1149. end;
  1150. function TFPInputFile.fileclose: boolean;
  1151. var OK: boolean;
  1152. begin
  1153. OK:=assigned(S);
  1154. if OK then
  1155. begin
  1156. S^.Reset;
  1157. Dispose(S, Done);
  1158. S:=nil;
  1159. OK:=true;
  1160. end;
  1161. fileclose:=OK;
  1162. end;
  1163. procedure tfpinputfile.filegettime;
  1164. var
  1165. dt : datetime;
  1166. hsec,wday : word;
  1167. begin
  1168. { current time }
  1169. dos.getdate(dt.year,dt.month,dt.day,wday);
  1170. dos.gettime(dt.hour,dt.min,dt.sec,hsec);
  1171. packtime(dt,filetime);
  1172. end;
  1173. procedure RegisterFPCompile;
  1174. begin
  1175. {$ifndef NOOBJREG}
  1176. RegisterType(RCompilerMessageListBox);
  1177. RegisterType(RCompilerMessageWindow);
  1178. {$endif}
  1179. end;
  1180. end.