fpcompil.pas 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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. procedure DoCompile(Mode: TCompileMode);
  106. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  107. procedure ParseUserScreen;
  108. procedure RegisterFPCompile;
  109. implementation
  110. uses
  111. {$ifdef Unix}
  112. {$ifdef VER1_0}
  113. Linux,
  114. {$else}
  115. Unix,
  116. {$endif}
  117. {$endif}
  118. {$ifdef go32v2}
  119. dpmiexcp,
  120. {$endif}
  121. {$ifdef win32}
  122. signals,
  123. {$endif}
  124. {$ifdef HasSignal}
  125. fpcatch,
  126. {$endif HasSignal}
  127. Dos,Video,
  128. StdDlg,App,tokens,
  129. {$ifdef FVISION}
  130. FVConsts,
  131. {$else}
  132. Commands,
  133. {$endif}
  134. CompHook, Compiler, systems, browcol,
  135. WEditor,
  136. FPString,FPRedir,FPDesk,
  137. FPUsrScr,FPHelp,
  138. {$ifndef NODEBUG}FPDebug,{$endif}
  139. FPConst,FPVars,FPUtils,FPIntf,FPSwitch;
  140. {$ifndef NOOBJREG}
  141. const
  142. RCompilerMessageListBox: TStreamRec = (
  143. ObjType: 1211;
  144. VmtLink: Ofs(TypeOf(TCompilerMessageListBox)^);
  145. Load: @TCompilerMessageListBox.Load;
  146. Store: @TCompilerMessageListBox.Store
  147. );
  148. RCompilerMessageWindow: TStreamRec = (
  149. ObjType: 1212;
  150. VmtLink: Ofs(TypeOf(TCompilerMessageWindow)^);
  151. Load: @TCompilerMessageWindow.Load;
  152. Store: @TCompilerMessageWindow.Store
  153. );
  154. {$endif}
  155. procedure ParseUserScreen;
  156. var
  157. y : longint;
  158. Text,Attr : String;
  159. DisplayCompilerWindow : boolean;
  160. cc: integer;
  161. procedure SearchBackTrace;
  162. var AText,ModuleName,st : String;
  163. row : longint;
  164. begin
  165. if pos(' 0x',Text)=1 then
  166. begin
  167. AText:=Text;
  168. Delete(Text,1,10);
  169. While pos(' ',Text)=1 do
  170. Delete(Text,1,1);
  171. if pos('of ',Text)>0 then
  172. begin
  173. ModuleName:=Copy(Text,pos('of ',Text)+3,255);
  174. While ModuleName[Length(ModuleName)]=' ' do
  175. Delete(ModuleName,Length(ModuleName),1);
  176. end
  177. else
  178. ModuleName:='';
  179. if pos('line ',Text)>0 then
  180. begin
  181. Text:=Copy(Text,Pos('line ',Text)+5,255);
  182. st:=Copy(Text,1,Pos(' ',Text)-1);
  183. Val(st,row,cc);
  184. end
  185. else
  186. row:=0;
  187. CompilerMessageWindow^.AddMessage(V_Fatal,AText
  188. ,ModuleName,row,1);
  189. DisplayCompilerWindow:=true;
  190. end;
  191. end;
  192. procedure InsertInMessages(Const TypeStr : String;_Type : longint;EnableDisplay : boolean);
  193. var p,p2,col,row : longint;
  194. St,ModuleName : string;
  195. begin
  196. p:=pos(TypeStr,Text);
  197. p2:=Pos('(',Text);
  198. if (p>0) and (p2>0) and (p2<p) then
  199. begin
  200. ModuleName:=Copy(Text,1,p2-1);
  201. st:=Copy(Text,p2+1,255);
  202. Val(Copy(st,1,pos(',',st)-1),row,cc);
  203. st:=Copy(st,Pos(',',st)+1,255);
  204. Val(Copy(st,1,pos(')',st)-1),col,cc);
  205. CompilerMessageWindow^.AddMessage(_type,Copy(Text,pos(':',Text)+1,255)
  206. ,ModuleName,row,col);
  207. If EnableDisplay then
  208. DisplayCompilerWindow:=true;
  209. end;
  210. end;
  211. begin
  212. if not assigned(UserScreen) then
  213. exit;
  214. DisplayCompilerWindow:=false;
  215. PushStatus('Parsing User Screen');
  216. for Y:=0 to UserScreen^.GetHeight do
  217. begin
  218. UserScreen^.GetLine(Y,Text,Attr);
  219. SearchBackTrace;
  220. InsertInMessages(' Fatal:',v_Fatal,true);
  221. InsertInMessages(' Error:',v_Error,true);
  222. InsertInMessages(' Warning:',v_Warning,false);
  223. InsertInMessages(' Note:',v_Note,false);
  224. InsertInMessages(' Info:',v_Info,false);
  225. InsertInMessages(' Hint:',v_Hint,false);
  226. end;
  227. if DisplayCompilerWindow then
  228. begin
  229. if not CompilerMessageWindow^.GetState(sfVisible) then
  230. CompilerMessageWindow^.Show;
  231. CompilerMessageWindow^.MakeFirst;
  232. CompilerMessageWindow^.MsgLB^.SelectFirstError;
  233. end;
  234. PopStatus;
  235. end;
  236. {*****************************************************************************
  237. TCompilerMessage
  238. *****************************************************************************}
  239. function TCompilerMessage.GetText(MaxLen: Sw_Integer): String;
  240. var
  241. ClassS: string[20];
  242. S: string;
  243. begin
  244. if TClass=
  245. V_Fatal then ClassS:=msg_class_Fatal else if TClass =
  246. V_Error then ClassS:=msg_class_Error else if TClass =
  247. V_Normal then ClassS:=msg_class_Normal else if TClass =
  248. V_Warning then ClassS:=msg_class_Warning else if TClass =
  249. V_Note then ClassS:=msg_class_Note else if TClass =
  250. V_Hint then ClassS:=msg_class_Hint
  251. {$ifdef VERBOSETXT}
  252. else if TClass =
  253. V_Macro then ClassS:=msg_class_macro else if TClass =
  254. V_Procedure then ClassS:=msg_class_procedure else if TClass =
  255. V_Conditional then ClassS:=msg_class_conditional else if TClass =
  256. V_Info then ClassS:=msg_class_info else if TClass =
  257. V_Status then ClassS:=msg_class_status else if TClass =
  258. V_Used then ClassS:=msg_class_used else if TClass =
  259. V_Tried then ClassS:=msg_class_tried else if TClass =
  260. V_Debug then ClassS:=msg_class_debug
  261. else
  262. ClassS:='???';
  263. {$else}
  264. else
  265. ClassS:='';
  266. {$endif}
  267. if ClassS<>'' then
  268. ClassS:=RExpand(ClassS,0)+': ';
  269. if assigned(Module) and
  270. (TClass<=V_ShowFile)
  271. {and (status.currentsource<>'') and (status.currentline>0)} then
  272. begin
  273. if Row>0 then
  274. begin
  275. if Col>0 then
  276. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  277. else
  278. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  279. end
  280. else
  281. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  282. end
  283. else
  284. S:=ClassS;
  285. if assigned(Text) then
  286. S:=S+Text^;
  287. if length(S)>MaxLen then
  288. S:=copy(S,1,MaxLen-2)+'..';
  289. GetText:=S;
  290. end;
  291. {*****************************************************************************
  292. TCompilerMessageListBox
  293. *****************************************************************************}
  294. function TCompilerMessageListBox.GetPalette: PPalette;
  295. const
  296. P: string[length(CBrowserListBox)] = CBrowserListBox;
  297. begin
  298. GetPalette:=@P;
  299. end;
  300. procedure TCompilerMessageListBox.SelectFirstError;
  301. function IsError(P : PCompilerMessage) : boolean;
  302. begin
  303. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  304. end;
  305. var
  306. P : PCompilerMessage;
  307. begin
  308. P:=List^.FirstThat(@IsError);
  309. If Assigned(P) then
  310. Begin
  311. FocusItem(List^.IndexOf(P));
  312. DrawView;
  313. End;
  314. end;
  315. {*****************************************************************************
  316. TCompilerMessageWindow
  317. *****************************************************************************}
  318. constructor TCompilerMessageWindow.Init;
  319. var R: TRect;
  320. HSB,VSB: PScrollBar;
  321. begin
  322. Desktop^.GetExtent(R);
  323. R.A.Y:=R.B.Y-7;
  324. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  325. HelpCtx:=hcCompilerMessagesWindow;
  326. AutoNumber:=true;
  327. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  328. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  329. Insert(HSB);
  330. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  331. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  332. Insert(VSB);
  333. GetExtent(R);
  334. R.Grow(-1,-1);
  335. New(MsgLB, Init(R, HSB, VSB));
  336. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  337. Insert(MsgLB);
  338. CompilerMessageWindow:=@self;
  339. end;
  340. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  341. begin
  342. if AClass>=V_Info then
  343. Line:=0;
  344. MsgLB^.AddItem(New(PCompilerMessage,Init(AClass, Msg, MsgLB^.AddModuleName(Module), Line, Column)));
  345. if (@Self=CompilerMessageWindow) and ((AClass = V_fatal) or (AClass = V_Error)) then
  346. begin
  347. if not GetState(sfVisible) then
  348. Show;
  349. if Desktop^.First<>PView(CompilerMessageWindow) then
  350. MakeFirst;
  351. end;
  352. end;
  353. procedure TCompilerMessageWindow.ClearMessages;
  354. begin
  355. MsgLB^.Clear;
  356. ReDraw;
  357. end;
  358. {procedure TCompilerMessageWindow.Updateinfo;
  359. begin
  360. if CompileShowed then
  361. begin
  362. InfoST^.SetText(
  363. RExpand(' Main file : '#1#$7f+Copy(SmartPath(MainFile),1,39),40)+#2+
  364. 'Total lines : '#1#$7e+IntToStr(Status.CompiledLines)+#2#13+
  365. RExpand(' Target : '#1#$7f+KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),40)+#2+
  366. 'Total errors : '#1#$7e+IntToStr(Status.ErrorCount)
  367. );
  368. if status.currentline>0 then
  369. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+'('+IntToStr(status.currentline)+')'#2)
  370. else
  371. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+#2);
  372. end;
  373. ReDraw;
  374. end;}
  375. procedure TCompilerMessageWindow.HandleEvent(var Event: TEvent);
  376. begin
  377. case Event.What of
  378. evBroadcast :
  379. case Event.Command of
  380. cmListFocusChanged :
  381. if Event.InfoPtr=MsgLB then
  382. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  383. end;
  384. end;
  385. inherited HandleEvent(Event);
  386. end;
  387. procedure TCompilerMessageWindow.SizeLimits(var Min, Max: TPoint);
  388. begin
  389. inherited SizeLimits(Min,Max);
  390. Min.X:=20;
  391. Min.Y:=4;
  392. end;
  393. procedure TCompilerMessageWindow.Close;
  394. begin
  395. Hide;
  396. end;
  397. function TCompilerMessageWindow.GetPalette: PPalette;
  398. const
  399. S : string[length(CBrowserWindow)] = CBrowserWindow;
  400. begin
  401. GetPalette:=@S;
  402. end;
  403. constructor TCompilerMessageWindow.Load(var S: TStream);
  404. begin
  405. inherited Load(S);
  406. GetSubViewPtr(S,MsgLB);
  407. end;
  408. procedure TCompilerMessageWindow.Store(var S: TStream);
  409. begin
  410. if MsgLB^.List=nil then
  411. MsgLB^.NewList(New(PCollection, Init(100,100)));
  412. inherited Store(S);
  413. PutSubViewPtr(S,MsgLB);
  414. end;
  415. procedure TCompilerMessageWindow.UpdateCommands;
  416. var Active: boolean;
  417. begin
  418. Active:=GetState(sfActive);
  419. SetCmdState(CompileCmds,Active);
  420. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  421. end;
  422. procedure TCompilerMessageWindow.SetState(AState: Word; Enable: Boolean);
  423. var OldState: word;
  424. begin
  425. OldState:=State;
  426. inherited SetState(AState,Enable);
  427. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  428. UpdateCommands;
  429. end;
  430. destructor TCompilerMessageWindow.Done;
  431. begin
  432. CompilerMessageWindow:=nil;
  433. inherited Done;
  434. end;
  435. {****************************************************************************
  436. CompilerStatusDialog
  437. ****************************************************************************}
  438. constructor TCompilerStatusDialog.Init;
  439. var R: TRect;
  440. begin
  441. R.Assign(0,0,50,11);
  442. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  443. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  444. GetExtent(R); R.B.Y:=11;
  445. R.Grow(-3,-2);
  446. New(ST, Init(R, ''));
  447. Insert(ST);
  448. GetExtent(R); R.B.Y:=11;
  449. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  450. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256,true));
  451. Insert(KeyST);
  452. { Reset Status infos see bug 1585 }
  453. Fillchar(Status,SizeOf(Status),#0);
  454. end;
  455. destructor TCompilerStatusDialog.Done;
  456. begin
  457. if @Self=CompilerStatusDialog then
  458. CompilerStatusDialog:=nil;
  459. Inherited Done;
  460. end;
  461. procedure TCompilerStatusDialog.Update;
  462. var
  463. StatusS,KeyS: string;
  464. const
  465. MaxFileNameSize = 46;
  466. begin
  467. {$ifdef TEMPHEAP}
  468. switch_to_base_heap;
  469. {$endif TEMPHEAP}
  470. case CompilationPhase of
  471. cpCompiling :
  472. begin
  473. ClearFormatParams;
  474. if Status.Compiling_current then
  475. begin
  476. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  477. MaxFileNameSize - Length(msg_compilingfile)));
  478. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  479. end
  480. else
  481. begin
  482. if Status.CurrentSource='' then
  483. StatusS:=''
  484. else
  485. begin
  486. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  487. MaxFileNameSize-Length(msg_loadingunit));
  488. AddFormatParamStr(StatusS);
  489. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  490. end;
  491. end;
  492. KeyS:=msg_hint_pressesctocancel;
  493. end;
  494. cpLinking :
  495. begin
  496. ClearFormatParams;
  497. AddFormatParamStr(ShrinkPath(ExeFile,
  498. MaxFileNameSize-Length(msg_linkingfile)));
  499. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  500. KeyS:=msg_hint_pleasewait;
  501. end;
  502. cpDone :
  503. begin
  504. StatusS:=msg_compiledone;
  505. KeyS:=msg_hint_compilesuccessfulpressenter;
  506. end;
  507. cpFailed :
  508. begin
  509. StatusS:=msg_failedtocompile;
  510. KeyS:=msg_hint_compilefailed;
  511. end;
  512. cpAborted :
  513. begin
  514. StatusS:=msg_compilationaborted;
  515. KeyS:=msg_hint_compileaborted;
  516. end;
  517. end;
  518. ClearFormatParams;
  519. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  520. MaxFileNameSize-Length('Main file: %s')));
  521. AddFormatParamStr(StatusS);
  522. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  523. AddFormatParamInt(Status.CurrentLine);
  524. AddFormatParamInt(MemAvail div 1024);
  525. AddFormatParamInt(Status.CompiledLines);
  526. AddFormatParamInt(Status.ErrorCount);
  527. ST^.SetText(
  528. FormatStrF(
  529. 'Main file: %s'#13+
  530. '%s'+#13#13+
  531. 'Target: %12s '+ 'Line number: %7d'+#13+
  532. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  533. 'Total errors: %5d',
  534. FormatParams)
  535. );
  536. KeyST^.SetText(^C+KeyS);
  537. {$ifdef TEMPHEAP}
  538. switch_to_temp_heap;
  539. {$endif TEMPHEAP}
  540. end;
  541. {****************************************************************************
  542. Compiler Hooks
  543. ****************************************************************************}
  544. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  545. var
  546. event : tevent;
  547. begin
  548. GetKeyEvent(Event);
  549. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  550. begin
  551. CompilationPhase:=cpAborted;
  552. { update info messages }
  553. if assigned(CompilerStatusDialog) then
  554. begin
  555. {$ifdef redircompiler}
  556. RedirDisableAll;
  557. {$endif}
  558. CompilerStatusDialog^.Update;
  559. {$ifdef redircompiler}
  560. RedirEnableAll;
  561. {$endif}
  562. end;
  563. CompilerStatus:=true;
  564. exit;
  565. end;
  566. { only display line info every 100 lines, ofcourse all other messages
  567. will be displayed directly }
  568. if (status.currentline mod 100=0) then
  569. begin
  570. { update info messages }
  571. {$ifdef redircompiler}
  572. RedirDisableAll;
  573. {$endif}
  574. if assigned(CompilerStatusDialog) then
  575. CompilerStatusDialog^.Update;
  576. {$ifdef redircompiler}
  577. RedirEnableAll;
  578. {$endif}
  579. { update memory usage }
  580. { HeapView^.Update; }
  581. end;
  582. CompilerStatus:=false;
  583. end;
  584. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  585. begin
  586. {$ifndef GABOR}
  587. if StopJmpValid then
  588. Longjmp(StopJmp,1)
  589. else
  590. Halt(1);
  591. {$endif}
  592. end;
  593. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  594. var t: longint;
  595. W: PSourceWindow;
  596. begin
  597. W:=EditorWindowFile(FExpand(filename));
  598. if Assigned(W) and (W^.Editor^.GetModified) then
  599. t:=Now
  600. else
  601. t:=def_getnamedfiletime(filename);
  602. CompilerGetNamedFileTime:=t;
  603. end;
  604. {$ifdef COMPILER_1_0}
  605. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  606. var f: pinputfile;
  607. W: PSourceWindow;
  608. begin
  609. W:=EditorWindowFile(FExpand(filename));
  610. if Assigned(W) and (W^.Editor^.GetModified) then
  611. f:=new(PFPInputFile, Init(W^.Editor))
  612. else
  613. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  614. if assigned(W) then
  615. W^.Editor^.CompileStamp:=CompileStamp;
  616. CompilerOpenInputFile:=f;
  617. end;
  618. {$else COMPILER_1_0}
  619. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  620. var f: tinputfile;
  621. W: PSourceWindow;
  622. begin
  623. W:=EditorWindowFile(FExpand(filename));
  624. if Assigned(W) and (W^.Editor^.GetModified) then
  625. f:=TFPInputFile.Create(W^.Editor)
  626. else
  627. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  628. if assigned(W) then
  629. W^.Editor^.CompileStamp:=CompileStamp;
  630. CompilerOpenInputFile:=f;
  631. end;
  632. {$endif COMPILER_1_0}
  633. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  634. begin
  635. {$ifdef TEMPHEAP}
  636. switch_to_base_heap;
  637. {$endif TEMPHEAP}
  638. CompilerComment:=false;
  639. {$ifndef DEV}
  640. if (status.verbosity and Level)=Level then
  641. {$endif}
  642. begin
  643. {$ifdef redircompiler}
  644. RedirDisableAll;
  645. {$endif}
  646. if not CompilerMessageWindow^.GetState(sfVisible) then
  647. CompilerMessageWindow^.Show;
  648. if Desktop^.First<>PView(CompilerMessageWindow) then
  649. CompilerMessageWindow^.MakeFirst;
  650. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  651. status.currentline,status.currentcolumn);
  652. { update info messages }
  653. if assigned(CompilerStatusDialog) then
  654. CompilerStatusDialog^.Update;
  655. {$ifdef DEBUG}
  656. {$ifndef NODEBUG}
  657. // def_gdb_stop(level);
  658. {$endif}
  659. {$endif DEBUG}
  660. {$ifdef redircompiler}
  661. RedirEnableAll;
  662. {$endif}
  663. { update memory usage }
  664. { HeapView^.Update; }
  665. end;
  666. {$ifdef TEMPHEAP}
  667. switch_to_temp_heap;
  668. {$endif TEMPHEAP}
  669. end;
  670. {****************************************************************************
  671. DoCompile
  672. ****************************************************************************}
  673. { This function must return '' if
  674. "Options|Directories|Exe and PPU directory" is empty }
  675. function GetExePath: string;
  676. var Path: string;
  677. I: Sw_integer;
  678. begin
  679. Path:='';
  680. if DirectorySwitches<>nil then
  681. with DirectorySwitches^ do
  682. for I:=0 to ItemCount-1 do
  683. begin
  684. if ItemParam(I)='-FE' then
  685. begin
  686. Path:=GetStringItem(I);
  687. Break;
  688. end;
  689. end;
  690. if Path<>'' then
  691. GetExePath:=CompleteDir(FExpand(Path))
  692. else
  693. GetExePath:='';
  694. end;
  695. function GetMainFile(Mode: TCompileMode): string;
  696. var FileName: string;
  697. P : PSourceWindow;
  698. begin
  699. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  700. if (PrimaryFileMain='') and (P=nil) then
  701. FileName:='' { nothing to compile }
  702. else
  703. begin
  704. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  705. FileName:=PrimaryFileMain
  706. else if assigned(P) then
  707. begin
  708. FileName:=P^.Editor^.FileName;
  709. if FileName='' then
  710. P^.Editor^.SaveAsk(true);
  711. FileName:=P^.Editor^.FileName;
  712. end
  713. else
  714. FileName:='';
  715. end;
  716. If (FileName<>'') then
  717. FileName:=FixFileName(FExpand(FileName));
  718. GetMainFile:=FileName;
  719. end;
  720. procedure ResetErrorMessages;
  721. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  722. begin
  723. if assigned(P) and
  724. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  725. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  726. end;
  727. begin
  728. Desktop^.ForEach(@ResetErrorLine);
  729. end;
  730. procedure DoCompile(Mode: TCompileMode);
  731. function IsExitEvent(E: TEvent): boolean;
  732. begin
  733. { following suggestion by Harsha Senanayake }
  734. IsExitEvent:=(E.What=evKeyDown);
  735. end;
  736. var
  737. s,FileName: string;
  738. ErrFile : Text;
  739. MustRestartDebugger,
  740. StoreStopJumpValid : boolean;
  741. StoreStopJmp : Jmp_buf;
  742. JmpRet,Error,LinkErrorCount : longint;
  743. E : TEvent;
  744. DummyView: PView;
  745. PPasFile : string[64];
  746. begin
  747. AskRecompileIfModifiedFlag:=true;
  748. { Get FileName }
  749. FileName:=GetMainFile(Mode);
  750. if FileName='' then
  751. begin
  752. ErrorBox(msg_nothingtocompile,nil);
  753. Exit;
  754. end else
  755. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  756. and with the file as primaryfile set it is already incompatible with itself
  757. if FileName='*' then
  758. begin
  759. ErrorBox(msg_cantcompileunsavedfile,nil);
  760. Exit;
  761. end; }
  762. PushStatus('Beginning compilation...');
  763. { Show Compiler Messages Window }
  764. { if not CompilerMessageWindow^.GetState(sfVisible) then
  765. CompilerMessageWindow^.Show;
  766. CompilerMessageWindow^.MakeFirst;}
  767. CompilerMessageWindow^.ClearMessages;
  768. { Tell why we compile }
  769. NeedRecompile(Mode,true);
  770. MainFile:=FileName;
  771. SetStatus('Writing switches to file...');
  772. WriteSwitches(SwitchesPath);
  773. { leaving open browsers leads to crashes !! (PM) }
  774. SetStatus('Preparing symbol info...');
  775. CloseAllBrowsers;
  776. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  777. WriteSymbolsFile(BrowserName);
  778. { MainFile:=FixFileName(FExpand(FileName));}
  779. SetStatus('Preparing to compile...'+NameOf(MainFile));
  780. If GetEXEPath<>'' then
  781. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt)
  782. else
  783. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+ExeExt;
  784. { Reset }
  785. CtrlBreakHit:=false;
  786. { Create Compiler Status Dialog }
  787. CompilationPhase:=cpCompiling;
  788. New(CompilerStatusDialog, Init);
  789. CompilerStatusDialog^.SetState(sfModal,true);
  790. { disable window closing }
  791. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  792. Application^.Insert(CompilerStatusDialog);
  793. CompilerStatusDialog^.Update;
  794. { hook compiler output }
  795. {$ifdef TP}
  796. do_status:=CompilerStatus;
  797. do_stop:=CompilerStop;
  798. do_comment:=CompilerComment;
  799. {$ifndef GABOR}do_openinputfile:=CompilerOpenInputFile;{$endif}
  800. do_getnamedfiletime:=CompilerGetNamedFileTime;
  801. {$else not TP}
  802. do_status:=@CompilerStatus;
  803. do_stop:=@CompilerStop;
  804. do_comment:=@CompilerComment;
  805. do_openinputfile:=@CompilerOpenInputFile;
  806. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  807. {$endif TP}
  808. do_initsymbolinfo:={$ifdef fpc}@{$endif}InitBrowserCol;
  809. do_donesymbolinfo:={$ifdef fpc}@{$endif}DoneBrowserCol;
  810. do_extractsymbolinfo:={$ifdef fpc}@{$endif}CreateBrowserCol;
  811. { Compile ! }
  812. {$ifdef redircompiler}
  813. ChangeRedirOut(FPOutFileName,false);
  814. ChangeRedirError(FPErrFileName,false);
  815. {$endif}
  816. {$ifdef TEMPHEAP}
  817. split_heap;
  818. switch_to_temp_heap;
  819. {$endif TEMPHEAP}
  820. { insert "" around name so that spaces are allowed }
  821. { only supported in compiler after 2000/01/14 PM }
  822. if pos(' ',FileName)>0 then
  823. FileName:='"'+FileName+'"';
  824. if mode=cBuild then
  825. FileName:='-B '+FileName;
  826. { tokens are created and distroed by compiler.compile !! PM }
  827. DoneTokens;
  828. {$ifdef COMPILER_1_0}
  829. PPasFile:='ppas'+source_os.scriptext;
  830. {$else COMPILER_1_0}
  831. PPasFile:='ppas'+source_info.scriptext;
  832. {$endif COMPILER_1_0}
  833. WUtils.DeleteFile(GetExePath+PpasFile);
  834. SetStatus('Compiling...');
  835. {$ifndef GABOR}
  836. StoreStopJumpValid:=StopJmpValid;
  837. StoreStopJmp:=StopJmp;
  838. StopJmpValid:=true;
  839. JmpRet:=SetJmp(StopJmp);
  840. if JmpRet=0 then
  841. begin
  842. inc(CompileStamp);
  843. ResetErrorMessages;
  844. {$ifndef NODEBUG}
  845. MustRestartDebugger:=false;
  846. if assigned(Debugger) then
  847. if Debugger^.HasExe then
  848. begin
  849. Debugger^.Reset;
  850. MustRestartDebugger:=true;
  851. end;
  852. {$endif NODEBUG}
  853. LastCompileTime := cardinal(Now);
  854. FpIntF.Compile(FileName,SwitchesPath);
  855. SetStatus('Finished compiling...');
  856. end
  857. else
  858. begin
  859. Inc(status.errorCount);
  860. {$ifdef HasSignal}
  861. Case JmpRet of
  862. SIGINT : s := 'Interrupted by Ctrl-C';
  863. SIGILL : s := 'Illegal instruction';
  864. SIGSEGV : s := 'Signal Segmentation violation';
  865. SIGFPE : s:='Floating point signal';
  866. else
  867. s:='Undetermined signal '+inttostr(JmpRet);
  868. end;
  869. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  870. {$endif HasSignal}
  871. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  872. SetStatus('Long jumped out of compilation...');
  873. end;
  874. StopJmpValid:=StoreStopJumpValid;
  875. StopJmp:=StoreStopJmp;
  876. {$endif}
  877. { tokens are created and distroyed by compiler.compile !! PM }
  878. InitTokens;
  879. if LinkAfter and
  880. ExistsFile(GetExePath+PpasFile) and
  881. (CompilationPhase<>cpAborted) and
  882. (status.errorCount=0) then
  883. begin
  884. CompilationPhase:=cpLinking;
  885. CompilerStatusDialog^.Update;
  886. SetStatus('Assembling and/or linking...');
  887. {$ifndef redircompiler}
  888. { At least here we want to catch output
  889. of batch file PM }
  890. ChangeRedirOut(FPOutFileName,false);
  891. ChangeRedirError(FPErrFileName,false);
  892. {$endif}
  893. {$ifdef Unix}
  894. Shell(GetExePath+PpasFile);
  895. Error:=LinuxError;
  896. {$else}
  897. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  898. Error:=DosError;
  899. {$endif}
  900. SetStatus('Finished linking...');
  901. RestoreRedirOut;
  902. RestoreRedirError;
  903. if Error<>0 then
  904. Inc(status.errorCount);
  905. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  906. begin
  907. Inc(status.errorCount);
  908. ClearFormatParams; AddFormatParamStr(ExeFile);
  909. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  910. {$I-}
  911. Assign(ErrFile,FPErrFileName);
  912. Reset(ErrFile);
  913. if EatIO<>0 then
  914. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  915. else
  916. begin
  917. LinkErrorCount:=0;
  918. While not eof(ErrFile) and (LinkErrorCount<25) do
  919. begin
  920. readln(ErrFile,s);
  921. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  922. inc(LinkErrorCount);
  923. end;
  924. if not eof(ErrFile) then
  925. begin
  926. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  927. CompilerMessageWindow^.AddMessage(V_error,
  928. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  929. end;
  930. Close(ErrFile);
  931. end;
  932. EatIO;
  933. {$I+}
  934. end
  935. else if error=0 then
  936. WUtils.DeleteFile(GetExePath+PpasFile);
  937. end;
  938. {$ifdef TEMPHEAP}
  939. switch_to_base_heap;
  940. {$endif TEMPHEAP}
  941. {$ifdef redircompiler}
  942. RestoreRedirOut;
  943. RestoreRedirError;
  944. {$endif}
  945. PopStatus;
  946. { Set end status }
  947. if not (CompilationPhase in [cpAborted,cpFailed]) then
  948. if (status.errorCount=0) then
  949. CompilationPhase:=cpDone
  950. else
  951. CompilationPhase:=cpFailed;
  952. { Show end status }
  953. { reenable window closing }
  954. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  955. CompilerStatusDialog^.Update;
  956. CompilerStatusDialog^.ReDraw;
  957. CompilerStatusDialog^.SetState(sfModal,false);
  958. if ((CompilationPhase in[cpAborted,cpDone,cpFailed]) or (ShowStatusOnError)) and (Mode<>cRun) then
  959. repeat
  960. CompilerStatusDialog^.GetEvent(E);
  961. if IsExitEvent(E)=false then
  962. CompilerStatusDialog^.HandleEvent(E);
  963. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  964. if assigned(CompilerStatusDialog) then
  965. begin
  966. Application^.Delete(CompilerStatusDialog);
  967. Dispose(CompilerStatusDialog, Done);
  968. end;
  969. CompilerStatusDialog:=nil;
  970. { end compilation returns true if the messagewindow should be removed }
  971. if CompilationPhase=cpDone then
  972. begin
  973. CompilerMessageWindow^.Hide;
  974. { This is the last compiled main file }
  975. PrevMainFile:=MainFile;
  976. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  977. end;
  978. { Update the app }
  979. Message(Application,evCommand,cmUpdate,nil);
  980. {$ifdef TEMPHEAP}
  981. releasetempheap;
  982. unsplit_heap;
  983. {$endif TEMPHEAP}
  984. DummyView:=Desktop^.First;
  985. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  986. begin
  987. DummyView:=DummyView^.NextView;
  988. end;
  989. with DummyView^ do
  990. if GetState(sfVisible) then
  991. begin
  992. SetState(sfSelected,false);
  993. SetState(sfSelected,true);
  994. end;
  995. if Assigned(CompilerMessageWindow) then
  996. with CompilerMessageWindow^ do
  997. begin
  998. if GetState(sfVisible) then
  999. begin
  1000. SetState(sfSelected,false);
  1001. SetState(sfSelected,true);
  1002. end;
  1003. if (status.errorCount>0) then
  1004. MsgLB^.SelectFirstError;
  1005. end;
  1006. { ^^^ we need this trick to reactivate the desktop }
  1007. EditorModified:=false;
  1008. {$ifndef NODEBUG}
  1009. if MustRestartDebugger then
  1010. InitDebugger;
  1011. {$endif NODEBUG}
  1012. { In case we have something that the compiler touched }
  1013. AskToReloadAllModifiedFiles;
  1014. { Try to read Browser info in again if compilation failure !! }
  1015. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1016. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1017. ReadSymbolsFile(BrowserName);
  1018. end;
  1019. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1020. var Need: boolean;
  1021. I: sw_integer;
  1022. SF: PSourceFile;
  1023. SourceTime,PPUTime,ObjTime: longint;
  1024. W: PSourceWindow;
  1025. begin
  1026. if Assigned(SourceFiles)=false then
  1027. Need:={(EditorModified=true)}true
  1028. else
  1029. begin
  1030. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1031. if Need then
  1032. begin
  1033. if verbose then
  1034. begin
  1035. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1036. CompilerMessageWindow^.AddMessage(V_info,
  1037. FormatStrF(msg_firstcompilationof,FormatParams),
  1038. '',0,0);
  1039. end;
  1040. end
  1041. else
  1042. for I:=0 to SourceFiles^.Count-1 do
  1043. begin
  1044. SF:=SourceFiles^.At(I);
  1045. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1046. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1047. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1048. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1049. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1050. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1051. writeln('------');}
  1052. { some units don't generate object files }
  1053. W:=EditorWindowFile(SF^.GetSourceFileName);
  1054. if (SourceTime<>-1) then
  1055. if ((SourceTime>PPUTime) or
  1056. ((SourceTime>ObjTime) and
  1057. (ObjTime<>-1))) or
  1058. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1059. begin
  1060. Need:=true;
  1061. if verbose then
  1062. begin
  1063. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1064. CompilerMessageWindow^.AddMessage(V_info,
  1065. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1066. SF^.GetSourceFileName,1,1);
  1067. end;
  1068. Break;
  1069. end;
  1070. end;
  1071. { writeln('Need?', Need); system.readln;}
  1072. end;
  1073. NeedRecompile:=Need;
  1074. end;
  1075. {$ifdef COMPILER_1_0}
  1076. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1077. begin
  1078. if not Assigned(AEditor) then Fail;
  1079. if inherited Init(AEditor^.FileName)=false then
  1080. Fail;
  1081. Editor:=AEditor;
  1082. end;
  1083. {$else COMPILER_1_0}
  1084. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1085. begin
  1086. if not Assigned(AEditor) then Fail;
  1087. if inherited Create(AEditor^.FileName)=nil then
  1088. Fail;
  1089. Editor:=AEditor;
  1090. end;
  1091. {$endif COMPILER_1_0}
  1092. function TFPInputFile.fileopen(const filename: string): boolean;
  1093. var OK: boolean;
  1094. begin
  1095. S:=New(PMemoryStream, Init(0,0));
  1096. OK:=Assigned(S) and (S^.Status=stOK);
  1097. if OK then OK:=Editor^.SaveToStream(S);
  1098. if OK then
  1099. S^.Seek(0)
  1100. else
  1101. begin
  1102. if Assigned(S) then Dispose(S, Done);
  1103. S:=nil;
  1104. end;
  1105. fileopen:=OK;
  1106. end;
  1107. function TFPInputFile.fileseek(pos: longint): boolean;
  1108. var OK: boolean;
  1109. begin
  1110. OK:=assigned(S);
  1111. if OK then
  1112. begin
  1113. S^.Reset;
  1114. S^.Seek(pos);
  1115. OK:=(S^.Status=stOK);
  1116. end;
  1117. fileseek:=OK;
  1118. end;
  1119. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1120. var
  1121. size: longint;
  1122. begin
  1123. if not assigned(S) then size:=0 else
  1124. begin
  1125. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1126. S^.Read(databuf,size);
  1127. if S^.Status<>stOK then size:=0;
  1128. end;
  1129. fileread:=size;
  1130. end;
  1131. function TFPInputFile.fileeof: boolean;
  1132. var EOF: boolean;
  1133. begin
  1134. EOF:=not assigned(S);
  1135. if not EOF then
  1136. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1137. fileeof:=EOF;
  1138. end;
  1139. function TFPInputFile.fileclose: boolean;
  1140. var OK: boolean;
  1141. begin
  1142. OK:=assigned(S);
  1143. if OK then
  1144. begin
  1145. S^.Reset;
  1146. Dispose(S, Done);
  1147. S:=nil;
  1148. OK:=true;
  1149. end;
  1150. fileclose:=OK;
  1151. end;
  1152. procedure RegisterFPCompile;
  1153. begin
  1154. {$ifndef NOOBJREG}
  1155. RegisterType(RCompilerMessageListBox);
  1156. RegisterType(RCompilerMessageWindow);
  1157. {$endif}
  1158. end;
  1159. end.
  1160. {
  1161. $Log$
  1162. Revision 1.7 2002-03-20 14:48:27 pierre
  1163. * moved StopJmp buffer to fpcatch unit
  1164. Revision 1.6 2001/11/13 01:58:34 carl
  1165. * Range check error fix
  1166. Revision 1.5 2001/10/03 10:21:43 pierre
  1167. fix for bug 1487
  1168. Revision 1.4 2001/09/18 11:33:26 pierre
  1169. * fix bug 1604
  1170. Revision 1.3 2001/09/12 09:25:01 pierre
  1171. * fix bug 1585
  1172. Revision 1.2 2001/08/05 02:01:47 peter
  1173. * FVISION define to compile with fvision units
  1174. Revision 1.1 2001/08/04 11:30:22 peter
  1175. * ide works now with both compiler versions
  1176. Revision 1.1.2.24 2001/06/07 16:41:12 jonas
  1177. * updated for stricter checking of @ for procvars
  1178. Revision 1.1.2.23 2001/05/09 15:42:08 pierre
  1179. Reset debugger before recompilation
  1180. Revision 1.1.2.22 2001/03/15 17:07:33 pierre
  1181. * avoid scrolling in Compiler Dialog window
  1182. Revision 1.1.2.21 2001/02/19 10:38:12 pierre
  1183. * completely stop the debugger while compiling
  1184. Revision 1.1.2.20 2001/02/13 16:04:01 pierre
  1185. * fixes for bugs 1280
  1186. Revision 1.1.2.19 2001/02/13 12:05:10 pierre
  1187. * fix for bug 1379
  1188. Revision 1.1.2.18 2000/12/30 22:52:27 peter
  1189. * check modified while in debug mode. But placed it between a
  1190. conditional again as it reports also if the file was already modified
  1191. before the first compile.
  1192. * remove unsaved file checks when compiling without primary file so it
  1193. works the same as with a primary file set.
  1194. Revision 1.1.2.17 2000/12/23 23:07:57 florian
  1195. * better message for unsaved files
  1196. Revision 1.1.2.16 2000/11/29 00:54:44 pierre
  1197. + preserve window number and save special windows
  1198. Revision 1.1.2.15 2000/11/27 11:44:05 pierre
  1199. * remove the Can't open fp__.err problem
  1200. Revision 1.1.2.14 2000/11/23 13:00:47 pierre
  1201. + better infos while compiling
  1202. Revision 1.1.2.13 2000/11/19 00:23:32 pierre
  1203. Task 23: nicer error message when trying to run unit or library
  1204. Revision 1.1.2.12 2000/11/16 23:06:30 pierre
  1205. * correct handling of Compile/Make if primary file is set
  1206. Revision 1.1.2.11 2000/11/14 17:40:02 pierre
  1207. * fix the linking problem in another directory
  1208. Revision 1.1.2.10 2000/11/14 09:23:55 marco
  1209. * Second batch
  1210. Revision 1.1.2.9 2000/11/06 16:55:48 pierre
  1211. * fix failure to recompile when file changed
  1212. Revision 1.1.2.8 2000/10/31 07:51:58 pierre
  1213. * recover gracefully if compiler generates a signal
  1214. Revision 1.1.2.7 2000/10/18 21:53:26 pierre
  1215. * several Gabor fixes
  1216. Revision 1.1.2.6 2000/10/09 16:28:24 pierre
  1217. * several linux enhancements
  1218. Revision 1.1.2.5 2000/10/03 16:15:57 pierre
  1219. * Use LongJmp in CompilerStop
  1220. Revision 1.1.2.4 2000/08/16 18:46:14 peter
  1221. [*] double clicking on a droplistbox caused GPF (due to invalid recurson)
  1222. [*] Make, Build now possible even in Compiler Messages Window
  1223. [+] when started in a new dir the IDE now ask whether to create a local
  1224. config, or to use the one located in the IDE dir
  1225. Revision 1.1.2.3 2000/08/15 03:40:53 peter
  1226. [*] no more fatal exits when the IDE can't find the error file (containing
  1227. the redirected assembler/linker output) after compilation
  1228. [*] hidden windows are now added always at the end of the Window List
  1229. [*] TINIFile parsed entries encapsulated in string delimiters incorrectly
  1230. [*] selection was incorrectly adjusted when typing in overwrite mode
  1231. [*] the line wasn't expanded when it's end was reached in overw. mode
  1232. [*] the IDE now tries to locate source files also in the user specified
  1233. unit dirs (for ex. as a response to 'Open at cursor' (Ctrl+Enter) )
  1234. [*] 'Open at cursor' is now aware of the extension (if specified)
  1235. Revision 1.1.2.2 2000/08/10 07:10:37 michael
  1236. * 'Auto save editor files' option did the opposite than expected, due
  1237. to a typo in FPIDE.PAS
  1238. + saving of source files before compilation is no longer neccessary.
  1239. When a modified editor file is involved in the compilation, then the
  1240. IDE saves it's contents to a memory stream and passes this to the
  1241. compiler (instead of the file on the disk)
  1242. Revision 1.1.2.1 2000/07/18 05:50:22 michael
  1243. + Merged Gabors fixes
  1244. Revision 1.1 2000/07/13 09:48:34 michael
  1245. + Initial import
  1246. Revision 1.60 2000/06/22 09:07:11 pierre
  1247. * Gabor changes: see fixes.txt
  1248. Revision 1.59 2000/06/16 08:50:40 pierre
  1249. + new bunch of Gabor's changes
  1250. Revision 1.58 2000/05/29 10:44:56 pierre
  1251. + New bunch of Gabor's changes: see fixes.txt
  1252. Revision 1.57 2000/05/02 08:42:27 pierre
  1253. * new set of Gabor changes: see fixes.txt
  1254. Revision 1.56 2000/04/25 08:42:32 pierre
  1255. * New Gabor changes : see fixes.txt
  1256. Revision 1.55 2000/04/18 11:42:36 pierre
  1257. lot of Gabor changes : see fixes.txt
  1258. Revision 1.54 2000/03/23 22:23:21 pierre
  1259. + Use PushStatus in ParseUserScreen
  1260. Revision 1.53 2000/03/21 23:33:18 pierre
  1261. adapted to wcedit addition by Gabor
  1262. Revision 1.52 2000/03/08 16:48:07 pierre
  1263. + Read BackTrace from UseScreen
  1264. Revision 1.51 2000/03/07 21:54:26 pierre
  1265. + ParseUserScreen
  1266. Revision 1.50 2000/02/06 23:41:42 pierre
  1267. + TCompilerMessageListBox.SelectFirstError
  1268. Revision 1.49 2000/01/25 00:26:35 pierre
  1269. + Browser info saving
  1270. Revision 1.48 2000/01/14 15:38:28 pierre
  1271. + support for long filenames with spaces for compilation
  1272. * avoid too long linker error output
  1273. Revision 1.47 2000/01/03 11:38:33 michael
  1274. Changes from Gabor
  1275. Revision 1.46 1999/12/01 17:08:19 pierre
  1276. * GetFileTime moved to wutils unit
  1277. Revision 1.45 1999/11/22 15:58:40 pierre
  1278. * fix for web bug 633
  1279. Revision 1.44 1999/11/21 01:44:34 pierre
  1280. + Use def_gdb_stop for easy GDB debugging
  1281. Revision 1.43 1999/11/18 13:49:56 pierre
  1282. + use IsExe var to know if we need to call ppas
  1283. Revision 1.42 1999/11/10 17:20:41 pierre
  1284. * Use fpredir.dosexecute
  1285. Revision 1.41 1999/10/25 16:34:19 pierre
  1286. * some units have no object files
  1287. led to wrong NeedRecompile result
  1288. Revision 1.40 1999/09/20 15:36:38 pierre
  1289. * adapted to new tokens unit
  1290. Revision 1.39 1999/09/16 14:34:57 pierre
  1291. + TBreakpoint and TWatch registering
  1292. + WatchesCollection and BreakpointsCollection stored in desk file
  1293. * Syntax highlighting was broken
  1294. Revision 1.38 1999/09/13 16:24:43 peter
  1295. + clock
  1296. * backspace unident like tp7
  1297. Revision 1.37 1999/09/09 14:19:16 pierre
  1298. * status should not be present in TCompilerMessage.GetText
  1299. Revision 1.36 1999/09/07 11:32:13 pierre
  1300. * fix for Linux ./ prepended to ppas.sh
  1301. * Build add '-B' option
  1302. * if linkAfter is set, get errors from linker
  1303. by redirecting files
  1304. Revision 1.35 1999/08/22 22:27:30 pierre
  1305. * not ppas call on compile failure
  1306. Revision 1.34 1999/08/16 18:25:13 peter
  1307. * Adjusting the selection when the editor didn't contain any line.
  1308. * Reserved word recognition redesigned, but this didn't affect the overall
  1309. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  1310. The syntax scanner loop is a bit slow but the main problem is the
  1311. recognition of special symbols. Switching off symbol processing boosts
  1312. the performance up to ca. 200%...
  1313. * The editor didn't allow copying (for ex to clipboard) of a single character
  1314. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  1315. * Compiler Messages window (actually the whole desktop) did not act on any
  1316. keypress when compilation failed and thus the window remained visible
  1317. + Message windows are now closed upon pressing Esc
  1318. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  1319. only when neccessary
  1320. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  1321. + LineSelect (Ctrl+K+L) implemented
  1322. * The IDE had problems closing help windows before saving the desktop
  1323. Revision 1.33 1999/08/03 20:22:26 peter
  1324. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  1325. + Desktop saving should work now
  1326. - History saved
  1327. - Clipboard content saved
  1328. - Desktop saved
  1329. - Symbol info saved
  1330. * syntax-highlight bug fixed, which compared special keywords case sensitive
  1331. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  1332. * with 'whole words only' set, the editor didn't found occourences of the
  1333. searched text, if the text appeared previously in the same line, but didn't
  1334. satisfied the 'whole-word' condition
  1335. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  1336. (ie. the beginning of the selection)
  1337. * when started typing in a new line, but not at the start (X=0) of it,
  1338. the editor inserted the text one character more to left as it should...
  1339. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  1340. * Shift shouldn't cause so much trouble in TCodeEditor now...
  1341. * Syntax highlight had problems recognizing a special symbol if it was
  1342. prefixed by another symbol character in the source text
  1343. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  1344. Revision 1.32 1999/07/12 13:14:13 pierre
  1345. * LineEnd bug corrected, now goes end of text even if selected
  1346. + Until Return for debugger
  1347. + Code for Quit inside GDB Window
  1348. Revision 1.31 1999/06/28 19:32:17 peter
  1349. * fixes from gabor
  1350. Revision 1.30 1999/06/28 15:59:04 pierre
  1351. * View Linking stage if external linking
  1352. Revision 1.29 1999/06/28 12:39:14 pierre
  1353. + close all browsers before compiling
  1354. Revision 1.28 1999/06/21 23:42:16 pierre
  1355. + LinkAfter and Esc to abort support added
  1356. Revision 1.27 1999/05/22 13:44:29 peter
  1357. * fixed couple of bugs
  1358. Revision 1.26 1999/05/02 14:29:35 peter
  1359. * fixed typo disableredir -> redirdisable
  1360. Revision 1.25 1999/04/29 22:58:09 pierre
  1361. + disabling of redirction in compiler dialogs
  1362. Revision 1.24 1999/04/29 09:36:11 peter
  1363. * fixed hotkeys with Compiler switches
  1364. * fixed compiler status dialog
  1365. * Run shows again the output
  1366. Revision 1.23 1999/04/07 21:55:43 peter
  1367. + object support for browser
  1368. * html help fixes
  1369. * more desktop saving things
  1370. * NODEBUG directive to exclude debugger
  1371. Revision 1.22 1999/04/01 10:27:07 pierre
  1372. + file(line) in start of message added
  1373. Revision 1.21 1999/04/01 10:15:17 pierre
  1374. * CurrSt,InfoSt and LineSt were not disposed correctly in done
  1375. * TComiplerMessage destructor first calls SetCompileShow(false)
  1376. to get proper cleaning up
  1377. Revision 1.20 1999/03/23 16:16:38 peter
  1378. * linux fixes
  1379. Revision 1.19 1999/03/19 16:04:27 peter
  1380. * new compiler dialog
  1381. Revision 1.18 1999/03/16 12:38:07 peter
  1382. * tools macro fixes
  1383. + tph writer
  1384. + first things for resource files
  1385. Revision 1.17 1999/03/12 01:13:56 peter
  1386. * flag if trytoopen should look for other extensions
  1387. + browser tab in the tools-compiler
  1388. Revision 1.16 1999/03/07 23:00:47 pierre
  1389. * Fix for path of executable
  1390. Revision 1.15 1999/03/01 15:41:50 peter
  1391. + Added dummy entries for functions not yet implemented
  1392. * MenuBar didn't update itself automatically on command-set changes
  1393. * Fixed Debugging/Profiling options dialog
  1394. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  1395. set
  1396. * efBackSpaceUnindents works correctly
  1397. + 'Messages' window implemented
  1398. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  1399. + Added TP message-filter support (for ex. you can call GREP thru
  1400. GREP2MSG and view the result in the messages window - just like in TP)
  1401. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  1402. so topic search didn't work...
  1403. * In FPHELP.PAS there were still context-variables defined as word instead
  1404. of THelpCtx
  1405. * StdStatusKeys() was missing from the statusdef for help windows
  1406. + Topic-title for index-table can be specified when adding a HTML-files
  1407. Revision 1.14 1999/02/22 12:46:56 peter
  1408. * small fixes for linux and grep
  1409. Revision 1.13 1999/02/22 11:51:33 peter
  1410. * browser updates from gabor
  1411. Revision 1.12 1999/02/22 11:29:36 pierre
  1412. + added col info in MessageItem
  1413. + grep uses HighLightExts and should work for linux
  1414. Revision 1.11 1999/02/08 09:31:00 florian
  1415. + some split heap stuff, in $ifdef TEMPHEAP
  1416. Revision 1.10 1999/02/05 13:51:39 peter
  1417. * unit name of FPSwitches -> FPSwitch which is easier to use
  1418. * some fixes for tp7 compiling
  1419. Revision 1.9 1999/02/05 13:06:28 pierre
  1420. * allow cmClose for Compilation Dialog box
  1421. Revision 1.8 1999/02/04 13:32:01 pierre
  1422. * Several things added (I cannot commit them independently !)
  1423. + added TBreakpoint and TBreakpointCollection
  1424. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  1425. + Breakpoint list in INIFile
  1426. * Select items now also depend of SwitchMode
  1427. * Reading of option '-g' was not possible !
  1428. + added search for -Fu args pathes in TryToOpen
  1429. + added code for automatic opening of FileDialog
  1430. if source not found
  1431. Revision 1.7 1999/01/21 11:54:11 peter
  1432. + tools menu
  1433. + speedsearch in symbolbrowser
  1434. * working run command
  1435. Revision 1.6 1999/01/15 16:12:43 peter
  1436. * fixed crash after compile
  1437. Revision 1.5 1999/01/14 21:42:19 peter
  1438. * source tracking from Gabor
  1439. Revision 1.4 1999/01/12 14:29:32 peter
  1440. + Implemented still missing 'switch' entries in Options menu
  1441. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  1442. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  1443. ASCII chars and inserted directly in the text.
  1444. + Added symbol browser
  1445. * splitted fp.pas to fpide.pas
  1446. Revision 1.3 1999/01/04 11:49:42 peter
  1447. * 'Use tab characters' now works correctly
  1448. + Syntax highlight now acts on File|Save As...
  1449. + Added a new class to syntax highlight: 'hex numbers'.
  1450. * There was something very wrong with the palette managment. Now fixed.
  1451. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  1452. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  1453. process revised
  1454. Revision 1.2 1998/12/28 15:47:42 peter
  1455. + Added user screen support, display & window
  1456. + Implemented Editor,Mouse Options dialog
  1457. + Added location of .INI and .CFG file
  1458. + Option (INI) file managment implemented (see bottom of Options Menu)
  1459. + Switches updated
  1460. + Run program
  1461. Revision 1.3 1998/12/22 10:39:40 peter
  1462. + options are now written/read
  1463. + find and replace routines
  1464. }