fpcompil.pas 37 KB

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