fpcompil.pas 48 KB

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