fpcompil.pas 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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, BaseUnix,
  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. case TClass and V_LevelMask of
  254. V_Fatal : ClassS:=msg_class_Fatal;
  255. V_Error : ClassS:=msg_class_Error;
  256. V_Normal : ClassS:=msg_class_Normal;
  257. V_Warning : ClassS:=msg_class_Warning;
  258. V_Note : ClassS:=msg_class_Note;
  259. V_Hint : ClassS:=msg_class_Hint;
  260. {$ifdef VERBOSETXT}
  261. V_Conditional : ClassS:=msg_class_conditional;
  262. V_Info : ClassS:=msg_class_info;
  263. V_Status : ClassS:=msg_class_status;
  264. V_Used : ClassS:=msg_class_used;
  265. V_Tried : ClassS:=msg_class_tried;
  266. V_Debug : ClassS:=msg_class_debug;
  267. else
  268. ClassS:='???';
  269. {$endif}
  270. else
  271. ClassS:='';
  272. end;
  273. if ClassS<>'' then
  274. ClassS:=RExpand(ClassS,0)+': ';
  275. if assigned(Module) and
  276. ((TClass and V_LineInfo)=V_LineInfo) then
  277. begin
  278. if Row>0 then
  279. begin
  280. if Col>0 then
  281. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  282. else
  283. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  284. end
  285. else
  286. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  287. end
  288. else
  289. S:=ClassS;
  290. if assigned(Text) then
  291. S:=S+Text^;
  292. if length(S)>MaxLen then
  293. S:=copy(S,1,MaxLen-2)+'..';
  294. GetText:=S;
  295. end;
  296. {*****************************************************************************
  297. TCompilerMessageListBox
  298. *****************************************************************************}
  299. function TCompilerMessageListBox.GetPalette: PPalette;
  300. const
  301. P: string[length(CBrowserListBox)] = CBrowserListBox;
  302. begin
  303. GetPalette:=@P;
  304. end;
  305. procedure TCompilerMessageListBox.SelectFirstError;
  306. function IsError(P : PCompilerMessage) : boolean;
  307. begin
  308. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  309. end;
  310. var
  311. P : PCompilerMessage;
  312. begin
  313. P:=List^.FirstThat(@IsError);
  314. If Assigned(P) then
  315. Begin
  316. FocusItem(List^.IndexOf(P));
  317. DrawView;
  318. End;
  319. end;
  320. {*****************************************************************************
  321. TCompilerMessageWindow
  322. *****************************************************************************}
  323. constructor TCompilerMessageWindow.Init;
  324. var R: TRect;
  325. HSB,VSB: PScrollBar;
  326. begin
  327. Desktop^.GetExtent(R);
  328. R.A.Y:=R.B.Y-7;
  329. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  330. HelpCtx:=hcCompilerMessagesWindow;
  331. AutoNumber:=true;
  332. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  333. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  334. Insert(HSB);
  335. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  336. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  337. Insert(VSB);
  338. GetExtent(R);
  339. R.Grow(-1,-1);
  340. New(MsgLB, Init(R, HSB, VSB));
  341. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  342. Insert(MsgLB);
  343. CompilerMessageWindow:=@self;
  344. end;
  345. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  346. begin
  347. {$ifdef COMPILER_1_0}
  348. if AClass>=V_Info then
  349. {$else}
  350. if (AClass and V_LineInfo)<>V_LineInfo then
  351. {$endif}
  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. case CompilationPhase of
  477. cpCompiling :
  478. begin
  479. ClearFormatParams;
  480. if Status.Compiling_current then
  481. begin
  482. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  483. MaxFileNameSize - Length(msg_compilingfile)));
  484. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  485. end
  486. else
  487. begin
  488. if Status.CurrentSource='' then
  489. StatusS:=''
  490. else
  491. begin
  492. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  493. MaxFileNameSize-Length(msg_loadingunit));
  494. AddFormatParamStr(StatusS);
  495. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  496. end;
  497. end;
  498. KeyS:=msg_hint_pressesctocancel;
  499. end;
  500. cpLinking :
  501. begin
  502. ClearFormatParams;
  503. AddFormatParamStr(ShrinkPath(ExeFile,
  504. MaxFileNameSize-Length(msg_linkingfile)));
  505. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  506. KeyS:=msg_hint_pleasewait;
  507. end;
  508. cpDone :
  509. begin
  510. StatusS:=msg_compiledone;
  511. KeyS:=msg_hint_compilesuccessfulpressenter;
  512. end;
  513. cpFailed :
  514. begin
  515. StatusS:=msg_failedtocompile;
  516. KeyS:=msg_hint_compilefailed;
  517. end;
  518. cpAborted :
  519. begin
  520. StatusS:=msg_compilationaborted;
  521. KeyS:=msg_hint_compileaborted;
  522. end;
  523. end;
  524. ClearFormatParams;
  525. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  526. MaxFileNameSize-Length('Main file: %s')));
  527. AddFormatParamStr(StatusS);
  528. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  529. AddFormatParamInt(Status.CurrentLine);
  530. AddFormatParamInt(MemAvail div 1024);
  531. AddFormatParamInt(Status.CompiledLines);
  532. AddFormatParamInt(Status.ErrorCount);
  533. ST^.SetText(
  534. FormatStrF(
  535. 'Main file: %s'#13+
  536. '%s'+#13#13+
  537. 'Target: %12s '+ 'Line number: %7d'+#13+
  538. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  539. 'Total errors: %5d',
  540. FormatParams)
  541. );
  542. KeyST^.SetText(^C+KeyS);
  543. end;
  544. {****************************************************************************
  545. Compiler Hooks
  546. ****************************************************************************}
  547. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  548. var
  549. event : tevent;
  550. begin
  551. GetKeyEvent(Event);
  552. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  553. begin
  554. CompilationPhase:=cpAborted;
  555. { update info messages }
  556. if assigned(CompilerStatusDialog) then
  557. begin
  558. {$ifdef redircompiler}
  559. RedirDisableAll;
  560. {$endif}
  561. CompilerStatusDialog^.Update;
  562. {$ifdef redircompiler}
  563. RedirEnableAll;
  564. {$endif}
  565. end;
  566. CompilerStatus:=true;
  567. exit;
  568. end;
  569. { only display line info every 100 lines, ofcourse all other messages
  570. will be displayed directly }
  571. if (status.currentline mod 100=0) then
  572. begin
  573. { update info messages }
  574. {$ifdef redircompiler}
  575. RedirDisableAll;
  576. {$endif}
  577. if assigned(CompilerStatusDialog) then
  578. CompilerStatusDialog^.Update;
  579. {$ifdef redircompiler}
  580. RedirEnableAll;
  581. {$endif}
  582. { update memory usage }
  583. { HeapView^.Update; }
  584. end;
  585. CompilerStatus:=false;
  586. end;
  587. const
  588. LONGJMPCALLED = -1;
  589. procedure CompilerStop(err: longint); {$ifndef FPC}far;{$endif}
  590. begin
  591. {$ifndef GABOR}
  592. {$ifdef HasSignal}
  593. if StopJmpValid then
  594. Longjmp(StopJmp,LONGJMPCALLED)
  595. else
  596. Halt(err);
  597. {$endif}
  598. {$endif}
  599. end;
  600. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  601. var t: longint;
  602. W: PSourceWindow;
  603. begin
  604. W:=EditorWindowFile(FExpand(filename));
  605. if Assigned(W) and (W^.Editor^.GetModified) then
  606. t:=Now
  607. else
  608. t:=def_getnamedfiletime(filename);
  609. CompilerGetNamedFileTime:=t;
  610. end;
  611. {$ifdef COMPILER_1_0}
  612. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  613. var f: pinputfile;
  614. W: PSourceWindow;
  615. begin
  616. if assigned(CompilingHiddenFile) and
  617. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  618. W:=CompilingHiddenFile
  619. else
  620. W:=EditorWindowFile(FExpand(filename));
  621. if Assigned(W) and (W^.Editor^.GetModified) then
  622. f:=new(PFPInputFile, Init(W^.Editor))
  623. else
  624. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  625. if assigned(W) then
  626. W^.Editor^.CompileStamp:=CompileStamp;
  627. CompilerOpenInputFile:=f;
  628. end;
  629. {$else COMPILER_1_0}
  630. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  631. var f: tinputfile;
  632. W: PSourceWindow;
  633. begin
  634. if assigned(CompilingHiddenFile) and
  635. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  636. W:=CompilingHiddenFile
  637. else
  638. W:=EditorWindowFile(FExpand(filename));
  639. if Assigned(W) and (W^.Editor^.GetModified) then
  640. f:=TFPInputFile.Create(W^.Editor)
  641. else
  642. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  643. if assigned(W) then
  644. W^.Editor^.CompileStamp:=CompileStamp;
  645. CompilerOpenInputFile:=f;
  646. end;
  647. {$endif COMPILER_1_0}
  648. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  649. begin
  650. CompilerComment:=false;
  651. if (status.verbosity and Level)<>0 then
  652. begin
  653. {$ifdef redircompiler}
  654. RedirDisableAll;
  655. {$endif}
  656. if not CompilerMessageWindow^.GetState(sfVisible) then
  657. CompilerMessageWindow^.Show;
  658. if Desktop^.First<>PView(CompilerMessageWindow) then
  659. CompilerMessageWindow^.MakeFirst;
  660. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  661. status.currentline,status.currentcolumn);
  662. { update info messages }
  663. if assigned(CompilerStatusDialog) then
  664. CompilerStatusDialog^.Update;
  665. {$ifdef DEBUG}
  666. {$ifndef NODEBUG}
  667. // def_gdb_stop(level);
  668. {$endif}
  669. {$endif DEBUG}
  670. {$ifdef redircompiler}
  671. RedirEnableAll;
  672. {$endif}
  673. { update memory usage }
  674. { HeapView^.Update; }
  675. end;
  676. end;
  677. {****************************************************************************
  678. DoCompile
  679. ****************************************************************************}
  680. { This function must return '' if
  681. "Options|Directories|Exe and PPU directory" is empty }
  682. function GetExePath: string;
  683. var Path: string;
  684. I: Sw_integer;
  685. begin
  686. Path:='';
  687. if DirectorySwitches<>nil then
  688. with DirectorySwitches^ do
  689. for I:=0 to ItemCount-1 do
  690. begin
  691. if ItemParam(I)='-FE' then
  692. begin
  693. Path:=GetStringItem(I);
  694. Break;
  695. end;
  696. end;
  697. if Path<>'' then
  698. GetExePath:=CompleteDir(FExpand(Path))
  699. else
  700. GetExePath:='';
  701. end;
  702. function GetMainFile(Mode: TCompileMode): string;
  703. var FileName: string;
  704. P : PSourceWindow;
  705. begin
  706. if assigned(CompilingHiddenFile) then
  707. P:=CompilingHiddenFile
  708. else
  709. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  710. if (PrimaryFileMain='') and (P=nil) then
  711. FileName:='' { nothing to compile }
  712. else
  713. begin
  714. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  715. FileName:=PrimaryFileMain
  716. else if assigned(P) then
  717. begin
  718. FileName:=P^.Editor^.FileName;
  719. if FileName='' then
  720. begin
  721. P^.Editor^.SaveAsk(true);
  722. FileName:=P^.Editor^.FileName;
  723. end;
  724. end
  725. else
  726. FileName:='';
  727. end;
  728. If (FileName<>'') then
  729. FileName:=FixFileName(FExpand(FileName));
  730. GetMainFile:=FileName;
  731. end;
  732. procedure ResetErrorMessages;
  733. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  734. begin
  735. if assigned(P) and
  736. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  737. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  738. end;
  739. begin
  740. Desktop^.ForEach(@ResetErrorLine);
  741. end;
  742. procedure DoCompile(Mode: TCompileMode);
  743. function IsExitEvent(E: TEvent): boolean;
  744. begin
  745. { following suggestion by Harsha Senanayake }
  746. IsExitEvent:=(E.What=evKeyDown);
  747. end;
  748. function GetTargetExeExt : string;
  749. begin
  750. {$ifdef COMPILER_1_0}
  751. GetTargetExeExt:=target_os.exeext;
  752. {$else COMPILER_1_0}
  753. GetTargetExeExt:=target_info.exeext;
  754. {$endif COMPILER_1_0}
  755. end;
  756. var
  757. s,FileName: string;
  758. ErrFile : Text;
  759. MustRestartDebugger,
  760. StoreStopJumpValid : boolean;
  761. StoreStopJmp : Jmp_buf;
  762. StoreExitProc : pointer;
  763. JmpRet,Error,LinkErrorCount : longint;
  764. E : TEvent;
  765. DummyView: PView;
  766. PPasFile : string[64];
  767. begin
  768. AskRecompileIfModifiedFlag:=true;
  769. { Get FileName }
  770. FileName:=GetMainFile(Mode);
  771. if FileName='' then
  772. begin
  773. ErrorBox(msg_nothingtocompile,nil);
  774. Exit;
  775. end else
  776. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  777. and with the file as primaryfile set it is already incompatible with itself
  778. if FileName='*' then
  779. begin
  780. ErrorBox(msg_cantcompileunsavedfile,nil);
  781. Exit;
  782. end; }
  783. PushStatus('Beginning compilation...');
  784. { Show Compiler Messages Window }
  785. { if not CompilerMessageWindow^.GetState(sfVisible) then
  786. CompilerMessageWindow^.Show;
  787. CompilerMessageWindow^.MakeFirst;}
  788. CompilerMessageWindow^.ClearMessages;
  789. { Tell why we compile }
  790. NeedRecompile(Mode,true);
  791. MainFile:=FileName;
  792. SetStatus('Writing switches to file...');
  793. WriteSwitches(SwitchesPath);
  794. { leaving open browsers leads to crashes !! (PM) }
  795. SetStatus('Preparing symbol info...');
  796. CloseAllBrowsers;
  797. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  798. WriteSymbolsFile(BrowserName);
  799. { MainFile:=FixFileName(FExpand(FileName));}
  800. SetStatus('Preparing to compile...'+NameOf(MainFile));
  801. { Reset }
  802. CtrlBreakHit:=false;
  803. { Create Compiler Status Dialog }
  804. CompilationPhase:=cpCompiling;
  805. if not assigned(CompilingHiddenFile) then
  806. begin
  807. New(CompilerStatusDialog, Init);
  808. CompilerStatusDialog^.SetState(sfModal,true);
  809. { disable window closing }
  810. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  811. Application^.Insert(CompilerStatusDialog);
  812. CompilerStatusDialog^.Update;
  813. end;
  814. { hook compiler output }
  815. do_status:=@CompilerStatus;
  816. do_stop:=@CompilerStop;
  817. do_comment:=@CompilerComment;
  818. do_openinputfile:=@CompilerOpenInputFile;
  819. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  820. do_initsymbolinfo:=@InitBrowserCol;
  821. do_donesymbolinfo:=@DoneBrowserCol;
  822. do_extractsymbolinfo:=@CreateBrowserCol;
  823. { Compile ! }
  824. {$ifdef redircompiler}
  825. ChangeRedirOut(FPOutFileName,false);
  826. ChangeRedirError(FPErrFileName,false);
  827. {$endif}
  828. { insert "" around name so that spaces are allowed }
  829. { only supported in compiler after 2000/01/14 PM }
  830. if pos(' ',FileName)>0 then
  831. FileName:='"'+FileName+'"';
  832. if mode=cBuild then
  833. FileName:='-B '+FileName;
  834. { tokens are created and distroed by compiler.compile !! PM }
  835. DoneTokens;
  836. {$ifdef COMPILER_1_0}
  837. PPasFile:='ppas'+source_os.scriptext;
  838. {$else COMPILER_1_0}
  839. PPasFile:='ppas'+source_info.scriptext;
  840. {$endif COMPILER_1_0}
  841. WUtils.DeleteFile(GetExePath+PpasFile);
  842. SetStatus('Compiling...');
  843. {$ifndef GABOR}
  844. {$ifdef HasSignal}
  845. StoreStopJumpValid:=StopJmpValid;
  846. StoreStopJmp:=StopJmp;
  847. {$endif HasSignal}
  848. StoreExitProc:=ExitProc;
  849. {$ifdef HasSignal}
  850. StopJmpValid:=true;
  851. JmpRet:=SetJmp(StopJmp);
  852. {$else}
  853. JmpRet:=0;
  854. {$endif HasSignal}
  855. if JmpRet=0 then
  856. begin
  857. inc(CompileStamp);
  858. ResetErrorMessages;
  859. {$ifndef NODEBUG}
  860. MustRestartDebugger:=false;
  861. if assigned(Debugger) then
  862. if Debugger^.HasExe then
  863. begin
  864. Debugger^.Reset;
  865. MustRestartDebugger:=true;
  866. end;
  867. {$endif NODEBUG}
  868. FpIntF.Compile(FileName,SwitchesPath);
  869. SetStatus('Finished compiling...');
  870. end
  871. else
  872. begin
  873. { We need to restore Exitproc to the value
  874. it was before calling FPintF.compile PM }
  875. ExitProc:=StoreExitProc;
  876. Inc(status.errorCount);
  877. {$ifdef HasSignal}
  878. Case JmpRet of
  879. LONGJMPCALLED : s:='Error';
  880. SIGINT : s := 'Interrupted by Ctrl-C';
  881. SIGILL : s := 'Illegal instruction';
  882. SIGSEGV : s := 'Signal Segmentation violation';
  883. SIGFPE : s:='Floating point signal';
  884. else
  885. s:='Undetermined signal '+inttostr(JmpRet);
  886. end;
  887. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  888. {$endif HasSignal}
  889. if JmpRet<>LONGJMPCALLED then
  890. begin
  891. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  892. SetStatus('Long jumped out of compilation...');
  893. end;
  894. end;
  895. {$ifdef HasSignal}
  896. StopJmpValid:=StoreStopJumpValid;
  897. StopJmp:=StoreStopJmp;
  898. {$endif HasSignal}
  899. {$endif}
  900. { Retrieve created exefile }
  901. If GetEXEPath<>'' then
  902. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+GetTargetExeExt)
  903. else
  904. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+GetTargetExeExt;
  905. { tokens are created and distroyed by compiler.compile !! PM }
  906. InitTokens;
  907. if LinkAfter and
  908. ExistsFile(GetExePath+PpasFile) and
  909. (CompilationPhase<>cpAborted) and
  910. (status.errorCount=0) then
  911. begin
  912. CompilationPhase:=cpLinking;
  913. if assigned(CompilerStatusDialog) then
  914. CompilerStatusDialog^.Update;
  915. SetStatus('Assembling and/or linking...');
  916. {$ifndef redircompiler}
  917. { At least here we want to catch output
  918. of batch file PM }
  919. ChangeRedirOut(FPOutFileName,false);
  920. ChangeRedirError(FPErrFileName,false);
  921. {$endif}
  922. {$ifdef Unix}
  923. {$ifdef ver1_0}
  924. Shell(GetExePath+PpasFile);
  925. Error:=LinuxError;
  926. {$else}
  927. error:=0;
  928. If Shell(GetExePath+PpasFile)=-1 Then
  929. Error:=fpgeterrno;
  930. {$endif}
  931. {$else}
  932. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  933. Error:=DosError;
  934. {$endif}
  935. SetStatus('Finished linking...');
  936. RestoreRedirOut;
  937. RestoreRedirError;
  938. if Error<>0 then
  939. Inc(status.errorCount);
  940. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  941. begin
  942. Inc(status.errorCount);
  943. ClearFormatParams; AddFormatParamStr(ExeFile);
  944. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  945. {$I-}
  946. Assign(ErrFile,FPErrFileName);
  947. Reset(ErrFile);
  948. if EatIO<>0 then
  949. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  950. else
  951. begin
  952. LinkErrorCount:=0;
  953. While not eof(ErrFile) and (LinkErrorCount<25) do
  954. begin
  955. readln(ErrFile,s);
  956. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  957. inc(LinkErrorCount);
  958. end;
  959. if not eof(ErrFile) then
  960. begin
  961. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  962. CompilerMessageWindow^.AddMessage(V_error,
  963. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  964. end;
  965. Close(ErrFile);
  966. end;
  967. EatIO;
  968. {$I+}
  969. end
  970. else if error=0 then
  971. WUtils.DeleteFile(GetExePath+PpasFile);
  972. end;
  973. {$ifdef redircompiler}
  974. RestoreRedirOut;
  975. RestoreRedirError;
  976. {$endif}
  977. PopStatus;
  978. { Set end status }
  979. if not (CompilationPhase in [cpAborted,cpFailed]) then
  980. if (status.errorCount=0) then
  981. begin
  982. CompilationPhase:=cpDone;
  983. LastCompileTime := cardinal(Now);
  984. end
  985. else
  986. CompilationPhase:=cpFailed;
  987. { Show end status }
  988. { reenable window closing }
  989. if assigned(CompilerStatusDialog) then
  990. begin
  991. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  992. CompilerStatusDialog^.Update;
  993. CompilerStatusDialog^.ReDraw;
  994. CompilerStatusDialog^.SetState(sfModal,false);
  995. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  996. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  997. repeat
  998. CompilerStatusDialog^.GetEvent(E);
  999. if IsExitEvent(E)=false then
  1000. CompilerStatusDialog^.HandleEvent(E);
  1001. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  1002. {if IsExitEvent(E) then
  1003. Application^.PutEvent(E);}
  1004. if assigned(CompilerStatusDialog) then
  1005. begin
  1006. Application^.Delete(CompilerStatusDialog);
  1007. Dispose(CompilerStatusDialog, Done);
  1008. end;
  1009. end;
  1010. CompilerStatusDialog:=nil;
  1011. { end compilation returns true if the messagewindow should be removed }
  1012. if CompilationPhase=cpDone then
  1013. begin
  1014. CompilerMessageWindow^.Hide;
  1015. { This is the last compiled main file }
  1016. PrevMainFile:=MainFile;
  1017. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1018. end;
  1019. { Update the app }
  1020. Message(Application,evCommand,cmUpdate,nil);
  1021. DummyView:=Desktop^.First;
  1022. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1023. begin
  1024. DummyView:=DummyView^.NextView;
  1025. end;
  1026. with DummyView^ do
  1027. if GetState(sfVisible) then
  1028. begin
  1029. SetState(sfSelected,false);
  1030. SetState(sfSelected,true);
  1031. end;
  1032. if Assigned(CompilerMessageWindow) then
  1033. with CompilerMessageWindow^ do
  1034. begin
  1035. if GetState(sfVisible) then
  1036. begin
  1037. SetState(sfSelected,false);
  1038. SetState(sfSelected,true);
  1039. end;
  1040. if (status.errorCount>0) then
  1041. MsgLB^.SelectFirstError;
  1042. end;
  1043. { ^^^ we need this trick to reactivate the desktop }
  1044. EditorModified:=false;
  1045. {$ifndef NODEBUG}
  1046. if MustRestartDebugger then
  1047. InitDebugger;
  1048. {$endif NODEBUG}
  1049. { In case we have something that the compiler touched }
  1050. AskToReloadAllModifiedFiles;
  1051. { Try to read Browser info in again if compilation failure !! }
  1052. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1053. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1054. ReadSymbolsFile(BrowserName);
  1055. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1056. AddAvailableUnitsToCodeComplete(false);
  1057. end;
  1058. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1059. var Need: boolean;
  1060. I: sw_integer;
  1061. SF: PSourceFile;
  1062. SourceTime,PPUTime,ObjTime: longint;
  1063. W: PSourceWindow;
  1064. begin
  1065. if Assigned(SourceFiles)=false then
  1066. Need:={(EditorModified=true)}true
  1067. else
  1068. begin
  1069. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1070. if Need then
  1071. begin
  1072. if verbose then
  1073. begin
  1074. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1075. CompilerMessageWindow^.AddMessage(V_info,
  1076. FormatStrF(msg_firstcompilationof,FormatParams),
  1077. '',0,0);
  1078. end;
  1079. end
  1080. else
  1081. for I:=0 to SourceFiles^.Count-1 do
  1082. begin
  1083. SF:=SourceFiles^.At(I);
  1084. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1085. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1086. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1087. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1088. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1089. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1090. writeln('------');}
  1091. { some units don't generate object files }
  1092. W:=EditorWindowFile(SF^.GetSourceFileName);
  1093. if (SourceTime<>-1) then
  1094. if ((SourceTime>PPUTime) or
  1095. ((SourceTime>ObjTime) and
  1096. (ObjTime<>-1))) or
  1097. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1098. begin
  1099. Need:=true;
  1100. if verbose then
  1101. begin
  1102. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1103. CompilerMessageWindow^.AddMessage(V_info,
  1104. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1105. SF^.GetSourceFileName,1,1);
  1106. end;
  1107. Break;
  1108. end;
  1109. end;
  1110. { writeln('Need?', Need); system.readln;}
  1111. end;
  1112. NeedRecompile:=Need;
  1113. end;
  1114. {$ifdef COMPILER_1_0}
  1115. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1116. begin
  1117. if not Assigned(AEditor) then Fail;
  1118. if inherited Init(AEditor^.FileName)=false then
  1119. Fail;
  1120. Editor:=AEditor;
  1121. end;
  1122. {$else COMPILER_1_0}
  1123. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1124. begin
  1125. if not Assigned(AEditor) then Fail;
  1126. if inherited Create(AEditor^.FileName)=nil then
  1127. Fail;
  1128. Editor:=AEditor;
  1129. end;
  1130. {$endif COMPILER_1_0}
  1131. function TFPInputFile.fileopen(const filename: string): boolean;
  1132. var OK: boolean;
  1133. begin
  1134. S:=New(PMemoryStream, Init(0,0));
  1135. OK:=Assigned(S) and (S^.Status=stOK);
  1136. if OK then OK:=Editor^.SaveToStream(S);
  1137. if OK then
  1138. S^.Seek(0)
  1139. else
  1140. begin
  1141. if Assigned(S) then Dispose(S, Done);
  1142. S:=nil;
  1143. end;
  1144. fileopen:=OK;
  1145. end;
  1146. function TFPInputFile.fileseek(pos: longint): boolean;
  1147. var OK: boolean;
  1148. begin
  1149. OK:=assigned(S);
  1150. if OK then
  1151. begin
  1152. S^.Reset;
  1153. S^.Seek(pos);
  1154. OK:=(S^.Status=stOK);
  1155. end;
  1156. fileseek:=OK;
  1157. end;
  1158. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1159. var
  1160. size: longint;
  1161. begin
  1162. if not assigned(S) then size:=0 else
  1163. begin
  1164. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1165. S^.Read(databuf,size);
  1166. if S^.Status<>stOK then size:=0;
  1167. end;
  1168. fileread:=size;
  1169. end;
  1170. function TFPInputFile.fileeof: boolean;
  1171. var EOF: boolean;
  1172. begin
  1173. EOF:=not assigned(S);
  1174. if not EOF then
  1175. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1176. fileeof:=EOF;
  1177. end;
  1178. function TFPInputFile.fileclose: boolean;
  1179. var OK: boolean;
  1180. begin
  1181. OK:=assigned(S);
  1182. if OK then
  1183. begin
  1184. S^.Reset;
  1185. Dispose(S, Done);
  1186. S:=nil;
  1187. OK:=true;
  1188. end;
  1189. fileclose:=OK;
  1190. end;
  1191. procedure RegisterFPCompile;
  1192. begin
  1193. {$ifndef NOOBJREG}
  1194. RegisterType(RCompilerMessageListBox);
  1195. RegisterType(RCompilerMessageWindow);
  1196. {$endif}
  1197. end;
  1198. end.
  1199. {
  1200. $Log$
  1201. Revision 1.28 2004-11-06 22:02:48 peter
  1202. * fixed resize helptext
  1203. Revision 1.27 2004/11/06 17:22:52 peter
  1204. * fixes for new fv
  1205. Revision 1.26 2004/11/05 00:00:33 peter
  1206. set exefile after compilation, before the target_info is not filled
  1207. Revision 1.25 2004/11/02 23:53:19 peter
  1208. * fixed crashes with ide and 1.9.x
  1209. Revision 1.24 2004/09/09 20:33:00 jonas
  1210. * made CompilerStop declaration compliant to new tstopprocedure type in
  1211. compiler
  1212. Revision 1.23 2003/11/14 17:29:38 marco
  1213. * linuxerrorcide
  1214. Revision 1.22 2003/03/28 09:55:46 armin
  1215. * Fixed TCompilerMessageWindow.AddMessage to see line numbers with 1.1
  1216. Revision 1.21 2003/03/27 14:11:53 pierre
  1217. * fix problem in CompilerComment procedure
  1218. Revision 1.20 2003/01/13 09:05:18 pierre
  1219. * fix error in last commit
  1220. Revision 1.19 2003/01/11 15:52:54 peter
  1221. * adapted for new 1.1 compiler verbosity
  1222. Revision 1.18 2002/12/02 13:58:29 pierre
  1223. * avoid longjmp messages if quitting after compilation error
  1224. Revision 1.17 2002/11/20 17:35:00 pierre
  1225. * use target_os.ExeExt for compiled executable
  1226. Revision 1.16 2002/10/23 19:19:40 hajny
  1227. * another bunch of missing HasSignal conditionals
  1228. Revision 1.15 2002/09/26 15:00:35 pierre
  1229. * fix problems with system unit is not present for __fp__ compilation
  1230. Revision 1.14 2002/09/13 22:30:50 pierre
  1231. * only fpc uses video unit
  1232. Revision 1.13 2002/09/09 06:53:54 pierre
  1233. * avoid to save file used by codecomplete
  1234. Revision 1.12 2002/09/07 15:40:42 peter
  1235. * old logs removed and tabs fixed
  1236. Revision 1.11 2002/09/05 08:45:40 pierre
  1237. * try to fix recompilation on changes problems
  1238. Revision 1.10 2002/09/04 14:07:12 pierre
  1239. + Enhance code complete by inserting unit symbols
  1240. Revision 1.9 2002/08/26 13:03:14 pierre
  1241. + add a lock to speed up parsing of userscreen
  1242. Revision 1.8 2002/04/10 22:37:37 pierre
  1243. * save and restore Exitproc if LongJmp called
  1244. Revision 1.7 2002/03/20 14:48:27 pierre
  1245. * moved StopJmp buffer to fpcatch unit
  1246. }