fpcompil.pas 49 KB

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