fpcompil.pas 37 KB

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