2
0

fp.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998-2000 by Berczi Gabor
  5. Main program of 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. program FP;
  13. {$ifdef IncRes}
  14. {$ifdef win32}
  15. {$R fpw32t.rc}
  16. {$R fpw32ico.rc}
  17. {$endif win32}
  18. {$endif IncRes}
  19. {$I globdir.inc}
  20. (**********************************************************************)
  21. (* CONDITIONAL DEFINES *)
  22. (* - NODEBUG No Debugging support *)
  23. (* - TP Turbo Pascal mode *)
  24. (* - i386 Target is an i386 IDE *)
  25. (**********************************************************************)
  26. uses
  27. {$ifdef EXTDEBUG}
  28. checkmem,
  29. {$endif EXTDEBUG}
  30. {$ifdef WITH_GDB}
  31. {$ifdef win32}
  32. fpcygwin,
  33. {$endif win32}
  34. {$endif WITH_GDB}
  35. {$ifdef IDEHeapTrc}
  36. PPheap,
  37. {$endif IDEHeapTrc}
  38. {$ifdef Use_DBGHEAP}
  39. dbgheap,
  40. {$endif Use_DBGHEAP}
  41. {$ifdef go32v2}
  42. dpmiexcp,
  43. {$endif go32v2}
  44. {$ifdef fpc}
  45. keyboard,video,mouse,
  46. {$endif fpc}
  47. {$ifdef HasSignal}
  48. fpcatch,
  49. {$endif HasSignal}
  50. Dos,Objects,
  51. BrowCol,Version,
  52. {$ifndef NODEBUG}
  53. gdbint,
  54. {$endif NODEBUG}
  55. FVConsts,
  56. Drivers,Views,App,Dialogs,HistList,
  57. Menus,StdDlg,Validate,
  58. WEditor,WCEdit,
  59. {$ifdef COLORSEL}
  60. ColorSel,
  61. {$endif COLORSEL}
  62. ASCIITab,
  63. WUtils,WViews,WHTMLScn,WHelp,
  64. FPIDE,FPCalc,FPCompil,FPString,
  65. FPIni,FPViews,FPConst,FPVars,FPUtils,FPHelp,FPSwitch,FPUsrScr,
  66. FPTools,
  67. {$ifndef NODEBUG}
  68. FPDebug,FPRegs,
  69. {$endif}
  70. FPTemplt,FPRedir,FPDesk,
  71. FPCodTmp,FPCodCmp,
  72. systems;
  73. {$ifdef fpc}
  74. Const
  75. DummyMouseDriver : TMouseDriver = (
  76. useDefaultQueue : true;
  77. InitDriver : nil;
  78. DoneDriver : nil;
  79. DetectMouse : nil;
  80. ShowMouse : nil;
  81. HideMouse : nil;
  82. GetMouseX : nil;
  83. GetMouseY : nil;
  84. GetMouseButtons : nil;
  85. SetMouseXY : nil;
  86. GetMouseEvent : nil;
  87. PollMouseEvent : nil;
  88. PutMouseEvent : nil;
  89. );
  90. {$endif fpc}
  91. {$ifdef DEBUG}
  92. const
  93. CloseImmediately : boolean = false;
  94. var
  95. StartTime : real;
  96. function getrealtime : real;
  97. var
  98. h,m,s,s100 : word;
  99. begin
  100. gettime(h,m,s,s100);
  101. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  102. end;
  103. {$endif DEBUG}
  104. procedure ProcessParams(BeforeINI: boolean);
  105. function IsSwitch(const Param: string): boolean;
  106. begin
  107. IsSwitch:=(Param<>'') and (Param[1]<>DirSep) { <- allow UNIX root-relative paths }
  108. and (Param[1] in ['-','/']); { <- but still accept dos switch char, eg. '/' }
  109. end;
  110. var I: Sw_integer;
  111. Param: string;
  112. begin
  113. for I:=1 to ParamCount do
  114. begin
  115. Param:=System.ParamStr(I);
  116. if IsSwitch(Param) then
  117. begin
  118. Param:=copy(Param,2,255);
  119. if Param<>'' then
  120. if UpcaseStr(copy(Param,1,2))='HM' then
  121. { HeapMonitor }
  122. begin
  123. if (copy(Param,3,1)='+') or (copy(Param,3,1)='') then
  124. StartupOptions:=StartupOptions or soHeapMonitor
  125. else
  126. if (copy(Param,3,1)='-') then
  127. StartupOptions:=StartupOptions and not soHeapMonitor;
  128. end else
  129. {$ifdef go32v2}
  130. if UpcaseStr(Param)='NOLFN' then
  131. begin
  132. LFNSupport:=false;
  133. end else
  134. {$endif go32v2}
  135. if UpcaseStr(Param)='README' then
  136. begin
  137. ShowReadme:=true;
  138. end else
  139. case Upcase(Param[1]) of
  140. 'C' : { custom config file (BP compatiblity) }
  141. if BeforeINI then
  142. begin
  143. if (length(Param)>=1) and (Param[1] in['=',':']) then
  144. Delete(Param,1,1); { eat separator }
  145. IniFileName:=Param;
  146. end;
  147. 'R' : { enter the directory last exited from (BP comp.) }
  148. begin
  149. Param:=copy(Param,2,255);
  150. if (Param='') or (Param='+') then
  151. StartupOptions:=StartupOptions or soReturnToLastDir
  152. else
  153. if (Param='-') then
  154. StartupOptions:=StartupOptions and (not soReturnToLastDir);
  155. end;
  156. 'S' :
  157. if Length(Param)=1 then
  158. begin
  159. UseMouse:=false;
  160. {$ifdef fpc}
  161. DoneMouse;
  162. SetMouseDriver(DummyMouseDriver);
  163. {$endif fpc}
  164. ButtonCount:=0;
  165. end;
  166. {$ifdef fpc}
  167. 'F' :
  168. if Length(Param)=1 then
  169. NoExtendedFrame:=true;
  170. {$ifdef Unix}
  171. 'T' : DebuggeeTTY:=Copy(Param,2,High(Param));
  172. {$endif Unix}
  173. { 'M' : TryToMaximizeScreen:=true;}
  174. {$endif fpc}
  175. {$ifdef DEBUG}
  176. 'Z' : UseOldBufStreamMethod:=true;
  177. 'X' : CloseImmediately:=true;
  178. {$endif DEBUG}
  179. end;
  180. end
  181. else
  182. if not BeforeINI then
  183. TryToOpenFile(nil,Param,0,0,{false}true);
  184. end;
  185. end;
  186. Procedure MyStreamError(Var S: TStream); {$ifndef FPC}far;{$endif}
  187. var ErrS: string;
  188. begin
  189. case S.Status of
  190. stGetError : ErrS:='Get of unregistered object type';
  191. stPutError : ErrS:='Put of unregistered object type';
  192. else ErrS:='';
  193. end;
  194. if ErrS<>'' then
  195. begin
  196. if Assigned(Application) then
  197. ErrorBox('Stream error: '+#13+ErrS,nil)
  198. else
  199. writeln('Error: ',ErrS);
  200. end;
  201. end;
  202. procedure DelTempFiles;
  203. begin
  204. DeleteFile(FPOutFileName);
  205. DeleteFile(FPErrFileName);
  206. DeleteFile(GDBOutFileName);
  207. DeleteFile(GDBOutPutFileName);
  208. DeleteFile(GREPOutName);
  209. DeleteFile(GREPErrName);
  210. end;
  211. procedure RegisterIDEObjects;
  212. begin
  213. RegisterApp;
  214. RegisterCodeComplete;
  215. RegisterCodeTemplates;
  216. {$ifdef COLORSEL}
  217. RegisterColorSel;
  218. {$endif COLORSEL}
  219. RegisterAsciiTab;
  220. RegisterDialogs;
  221. RegisterWEditor;
  222. RegisterWCEdit;
  223. RegisterFPCalc;
  224. RegisterFPCompile;
  225. RegisterFPTools;
  226. RegisterFPViews;
  227. {$ifndef NODEBUG}
  228. RegisterFPDebugViews;
  229. RegisterFPRegsViews;
  230. {$endif}
  231. RegisterMenus;
  232. RegisterStdDlg;
  233. RegisterSymbols;
  234. RegisterObjects;
  235. RegisterValidate;
  236. RegisterViews;
  237. RegisterWHTMLScan;
  238. RegisterWUtils;
  239. RegisterWViews;
  240. end;
  241. var CanExit : boolean;
  242. SetJmpRes : longint;
  243. StoreExitProc : pointer;
  244. ErrS : String;
  245. P : record
  246. l1 : longint;
  247. s : pstring;
  248. end;
  249. {$ifdef win32}
  250. ShowMouseExe : string;
  251. {$endif win32}
  252. const
  253. ExitIntercepted : boolean = false;
  254. SeenExitCode : longint =0;
  255. SeenErrorAddr : pointer = nil;
  256. UserWantsToGoOn: boolean = false;
  257. procedure InterceptExit;
  258. begin
  259. {$IFDEF HasSignal}
  260. if StopJmpValid then
  261. begin
  262. ExitIntercepted:=true;
  263. SeenExitCode:=ExitCode;
  264. SeenErrorAddr:=ErrorAddr;
  265. LongJmp(StopJmp,1);
  266. end;
  267. {$ENDIF}
  268. end;
  269. BEGIN
  270. {$IFDEF HasSignal}
  271. EnableCatchSignals;
  272. {$ENDIF}
  273. {$ifdef DEV}
  274. HeapLimit:=4096;
  275. {$endif}
  276. HistorySize:=16384;
  277. { Startup info }
  278. writeln('þ Free Pascal IDE Version '+VersionStr+' ['+{$i %date%}+']');
  279. writeln('þ Compiler Version '+Version_String);
  280. {$ifdef WITH_GDB}
  281. writeln('þ GBD Version '+GDBVersion);
  282. {$ifdef win32}
  283. writeln('þ Cygwin "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  284. CheckCygwinVersion;
  285. {$endif win32}
  286. {$endif WITH_GDB}
  287. ProcessParams(true);
  288. {$ifdef DEBUG}
  289. StartTime:=getrealtime;
  290. {$endif DEBUG}
  291. InitDirs;
  292. RegisterIDEObjects;
  293. StreamError:=@MyStreamError;
  294. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  295. {$ifdef VESA}
  296. InitVESAScreenModes;
  297. {$endif}
  298. InitRedir;
  299. {$ifndef NODEBUG}
  300. InitBreakpoints;
  301. InitWatches;
  302. {$endif}
  303. InitReservedWords;
  304. InitHelpFiles;
  305. InitSwitches;
  306. InitINIFile;
  307. InitUserScreen;
  308. InitTools;
  309. InitTemplates;
  310. InitCodeTemplates;
  311. InitCodeComplete;
  312. { init target information etc. }
  313. InitSystems;
  314. IDEApp.Init;
  315. CheckINIFile;
  316. ReadSwitches(SwitchesPath);
  317. { load all options after init because of open files }
  318. ReadINIFile;
  319. InitDesktopFile;
  320. LoadDesktop;
  321. { Handle Standard Units }
  322. if UseAllUnitsInCodeComplete then
  323. AddAvailableUnitsToCodeComplete(false);
  324. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  325. AddStandardUnitsToCodeComplete;
  326. { why are the screen contents parsed at startup? Gabor
  327. to be able to find location of error in last compilation
  328. from command line PM }
  329. ParseUserScreen;
  330. { Update IDE }
  331. IDEApp.Update;
  332. IDEApp.UpdateMode;
  333. IDEApp.UpdateTarget;
  334. ProcessParams(false);
  335. if ShowReadme then
  336. begin
  337. PutCommand(Application,evCommand,cmShowReadme,nil);
  338. ShowReadme:=false; { do not show next time }
  339. end;
  340. StoreExitProc:=ExitProc;
  341. ExitProc:=@InterceptExit;
  342. repeat
  343. {$IFDEF HasSignal}
  344. SetJmpRes:=setjmp(StopJmp);
  345. StopJmpValid:=true;
  346. {$ENDIF}
  347. UserWantsToGoOn:=false;
  348. if SetJmpRes=0 then
  349. begin
  350. {$ifdef DEBUG}
  351. if not CloseImmediately then
  352. {$endif DEBUG}
  353. IDEApp.Run;
  354. end
  355. else
  356. begin
  357. if (SetJmpRes=1) and ExitIntercepted then
  358. begin
  359. { If ExitProc=@InterceptExit then
  360. ExitProc:=StoreExitProc;}
  361. Str(SeenExitCode,ErrS);
  362. if Assigned(Application) then
  363. begin
  364. P.l1:=SeenExitCode;
  365. ErrS:=hexstr(longint(SeenErrorAddr),8);
  366. P.s:=@ErrS;
  367. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  368. UserWantsToGoOn:=true;
  369. end
  370. else
  371. writeln('Abnormal exit error: ',ErrS);
  372. end
  373. else
  374. begin
  375. Str(SetJmpRes,ErrS);
  376. { Longjmp was called by fpcatch }
  377. if Assigned(Application) then
  378. begin
  379. P.l1:=SetJmpRes;
  380. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  381. UserWantsToGoOn:=true;
  382. end
  383. else
  384. writeln('Signal error: ',ErrS);
  385. end;
  386. end;
  387. if (AutoSaveOptions and asEditorFiles)=0 then
  388. CanExit:=IDEApp.AskSaveAll
  389. else
  390. CanExit:=IDEApp.SaveAll;
  391. {$IFDEF HasSignal}
  392. StopJmpValid:=false;
  393. {$ENDIF}
  394. if (SetJmpRes<>0) then
  395. begin
  396. if (not CanExit) or UserWantsToGoOn then
  397. begin
  398. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  399. CanExit:=true
  400. else
  401. CanExit:=false;
  402. end
  403. else
  404. begin
  405. ErrorBox(leaving_after_error,nil);
  406. end;
  407. end;
  408. until CanExit;
  409. If ExitProc=pointer(@InterceptExit) then
  410. ExitProc:=StoreExitProc;
  411. IDEApp.AutoSave;
  412. DoneDesktopFile;
  413. DelTempFiles;
  414. IDEApp.Done;
  415. WriteSwitches(SwitchesPath);
  416. {$IFDEF HasSignal}
  417. DisableCatchSignals;
  418. {$ENDIF}
  419. DoneCodeComplete;
  420. DoneCodeTemplates;
  421. DoneTemplates;
  422. DoneTools;
  423. DoneUserScreen;
  424. DoneSwitches;
  425. DoneHelpFiles;
  426. DoneHelpFilesTypes;
  427. DoneReservedWords;
  428. DoneToolMessages;
  429. DoneBrowserCol;
  430. {$ifndef NODEBUG}
  431. DoneDebugger;
  432. DoneBreakpoints;
  433. DoneWatches;
  434. {$endif}
  435. {$ifdef fpc}
  436. {$ifdef unix}
  437. Video.ClearScreen;
  438. {$endif unix}
  439. Video.DoneVideo;
  440. Keyboard.DoneKeyboard;
  441. {$endif fpc}
  442. {$ifdef VESA}
  443. DoneVESAScreenModes;
  444. {$endif}
  445. {$ifdef unix}
  446. Keyboard.RestoreStartMode;
  447. {$endif unix}
  448. StreamError:=nil;
  449. {$ifdef DEBUG}
  450. if CloseImmediately then
  451. writeln('Used time is ',getrealtime-StartTime:0:2);
  452. {$endif DEBUG}
  453. END.
  454. {
  455. $Log$
  456. Revision 1.26 2004-11-14 21:45:28 florian
  457. * fixed non working mouse after tools call
  458. * better handling of source/target info
  459. * more info in about dialog
  460. * better info in compiler status dialiog
  461. Revision 1.25 2004/11/08 20:28:25 peter
  462. * Breakpoints are now deleted when removed from source, disabling is
  463. still possible from the breakpoint list
  464. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  465. FV and 1.9.x compilers
  466. * Run directory added to Run menu
  467. * Useless programinfo window removed
  468. Revision 1.24 2004/11/05 00:21:56 peter
  469. version info at startup
  470. Revision 1.23 2003/09/29 14:36:59 peter
  471. * win32 fixed
  472. Revision 1.22 2003/06/04 15:06:14 peter
  473. * histsize increased
  474. Revision 1.21 2003/01/29 00:30:53 pierre
  475. * load CheckMem as first if EXTDEBUG is defined
  476. Revision 1.20 2003/01/28 16:53:47 pierre
  477. * only include fpcygwin if libgdb is linked in
  478. Revision 1.19 2003/01/14 16:24:52 pierre
  479. * only insert win32 resource if IncRes is defined
  480. Revision 1.18 2003/01/07 00:29:13 pierre
  481. + win32 version infos
  482. Revision 1.17 2002/12/12 00:08:09 pierre
  483. Use fpregs unit
  484. Revision 1.16 2002/11/28 12:49:20 pierre
  485. * enable signals catching earlier
  486. Revision 1.15 2002/10/30 22:12:13 pierre
  487. * use ppheap with IDEHEAPTRC conditional
  488. Revision 1.14 2002/10/12 19:43:07 hajny
  489. * missing HasSignal conditionals added (needed for FPC/2)
  490. Revision 1.13 2002/09/10 12:19:14 pierre
  491. * use faster method for loading files by default
  492. Revision 1.12 2002/09/09 06:59:16 pierre
  493. * new debug options added
  494. Revision 1.11 2002/09/07 15:40:41 peter
  495. * old logs removed and tabs fixed
  496. Revision 1.10 2002/09/04 14:07:12 pierre
  497. + Enhance code complete by inserting unit symbols
  498. Revision 1.9 2002/05/29 22:29:42 pierre
  499. Asciitab now in fvision
  500. Revision 1.8 2002/04/12 11:28:55 pierre
  501. + use fpcygwin unit for win32 debug IDE
  502. Revision 1.7 2002/04/12 09:00:01 pierre
  503. * enhance internal error handling
  504. Revision 1.6 2002/03/28 16:32:48 pierre
  505. * clearscrenn at exit for unix
  506. Revision 1.5 2002/03/20 14:56:41 pierre
  507. * correct last commit
  508. Revision 1.4 2002/03/20 14:53:37 pierre
  509. + rescue handlers in main loop
  510. Revision 1.3 2002/01/09 09:46:10 pierre
  511. * fix problems with -S option
  512. }