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. {$ifndef NODEBUG}
  31. {$ifdef win32}
  32. fpcygwin,
  33. {$endif win32}
  34. {$endif NODEBUG}
  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. const
  250. ExitIntercepted : boolean = false;
  251. SeenExitCode : longint =0;
  252. SeenErrorAddr : pointer = nil;
  253. UserWantsToGoOn: boolean = false;
  254. procedure InterceptExit;
  255. begin
  256. {$IFDEF HasSignal}
  257. if StopJmpValid then
  258. begin
  259. ExitIntercepted:=true;
  260. SeenExitCode:=ExitCode;
  261. SeenErrorAddr:=ErrorAddr;
  262. LongJmp(StopJmp,1);
  263. end;
  264. {$ENDIF}
  265. end;
  266. BEGIN
  267. {$IFDEF HasSignal}
  268. EnableCatchSignals;
  269. {$ENDIF}
  270. {$ifdef DEV}
  271. HeapLimit:=4096;
  272. {$endif}
  273. HistorySize:=16384;
  274. { Startup info }
  275. writeln('þ Free Pascal IDE Version '+VersionStr+' ['+{$i %date%}+']');
  276. writeln('þ Compiler Version '+Version_String);
  277. {$ifndef NODEBUG}
  278. writeln('þ GBD Version '+GDBVersion);
  279. {$ifdef win32}
  280. writeln('þ Cygwin "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  281. CheckCygwinVersion;
  282. {$endif win32}
  283. {$endif NODEBUG}
  284. ProcessParams(true);
  285. {$ifdef DEBUG}
  286. StartTime:=getrealtime;
  287. {$endif DEBUG}
  288. InitDirs;
  289. RegisterIDEObjects;
  290. StreamError:=@MyStreamError;
  291. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  292. {$ifdef VESA}
  293. InitVESAScreenModes;
  294. {$endif}
  295. InitRedir;
  296. {$ifndef NODEBUG}
  297. InitBreakpoints;
  298. InitWatches;
  299. {$endif}
  300. InitReservedWords;
  301. InitHelpFiles;
  302. InitSwitches;
  303. InitINIFile;
  304. InitUserScreen;
  305. InitTools;
  306. InitTemplates;
  307. InitCodeTemplates;
  308. InitCodeComplete;
  309. { init target information etc. }
  310. InitSystems;
  311. IDEApp.Init;
  312. CheckINIFile;
  313. ReadSwitches(SwitchesPath);
  314. { load all options after init because of open files }
  315. ReadINIFile;
  316. InitDesktopFile;
  317. LoadDesktop;
  318. { Handle Standard Units }
  319. if UseAllUnitsInCodeComplete then
  320. AddAvailableUnitsToCodeComplete(false);
  321. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  322. AddStandardUnitsToCodeComplete;
  323. { why are the screen contents parsed at startup? Gabor
  324. to be able to find location of error in last compilation
  325. from command line PM }
  326. ParseUserScreen;
  327. { Update IDE }
  328. IDEApp.Update;
  329. IDEApp.UpdateMode;
  330. IDEApp.UpdateTarget;
  331. ProcessParams(false);
  332. if ShowReadme then
  333. begin
  334. PutCommand(Application,evCommand,cmShowReadme,nil);
  335. ShowReadme:=false; { do not show next time }
  336. end;
  337. StoreExitProc:=ExitProc;
  338. ExitProc:=@InterceptExit;
  339. repeat
  340. {$IFDEF HasSignal}
  341. SetJmpRes:=setjmp(StopJmp);
  342. StopJmpValid:=true;
  343. {$ENDIF}
  344. UserWantsToGoOn:=false;
  345. if SetJmpRes=0 then
  346. begin
  347. {$ifdef DEBUG}
  348. if not CloseImmediately then
  349. {$endif DEBUG}
  350. IDEApp.Run;
  351. end
  352. else
  353. begin
  354. if (SetJmpRes=1) and ExitIntercepted then
  355. begin
  356. { If ExitProc=@InterceptExit then
  357. ExitProc:=StoreExitProc;}
  358. Str(SeenExitCode,ErrS);
  359. if Assigned(Application) then
  360. begin
  361. P.l1:=SeenExitCode;
  362. ErrS:=hexstr(longint(SeenErrorAddr),8);
  363. P.s:=@ErrS;
  364. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  365. UserWantsToGoOn:=true;
  366. end
  367. else
  368. writeln('Abnormal exit error: ',ErrS);
  369. end
  370. else
  371. begin
  372. Str(SetJmpRes,ErrS);
  373. { Longjmp was called by fpcatch }
  374. if Assigned(Application) then
  375. begin
  376. P.l1:=SetJmpRes;
  377. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  378. UserWantsToGoOn:=true;
  379. end
  380. else
  381. writeln('Signal error: ',ErrS);
  382. end;
  383. end;
  384. if (AutoSaveOptions and asEditorFiles)=0 then
  385. CanExit:=IDEApp.AskSaveAll
  386. else
  387. CanExit:=IDEApp.SaveAll;
  388. {$IFDEF HasSignal}
  389. StopJmpValid:=false;
  390. {$ENDIF}
  391. if (SetJmpRes<>0) then
  392. begin
  393. if (not CanExit) or UserWantsToGoOn then
  394. begin
  395. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  396. CanExit:=true
  397. else
  398. CanExit:=false;
  399. end
  400. else
  401. begin
  402. ErrorBox(leaving_after_error,nil);
  403. end;
  404. end;
  405. until CanExit;
  406. If ExitProc=pointer(@InterceptExit) then
  407. ExitProc:=StoreExitProc;
  408. IDEApp.AutoSave;
  409. DoneDesktopFile;
  410. DelTempFiles;
  411. IDEApp.Done;
  412. WriteSwitches(SwitchesPath);
  413. {$IFDEF HasSignal}
  414. DisableCatchSignals;
  415. {$ENDIF}
  416. DoneCodeComplete;
  417. DoneCodeTemplates;
  418. DoneTemplates;
  419. DoneTools;
  420. DoneUserScreen;
  421. DoneSwitches;
  422. DoneHelpFiles;
  423. DoneHelpFilesTypes;
  424. DoneReservedWords;
  425. DoneToolMessages;
  426. DoneBrowserCol;
  427. {$ifndef NODEBUG}
  428. DoneDebugger;
  429. DoneBreakpoints;
  430. DoneWatches;
  431. {$endif}
  432. {$ifdef fpc}
  433. {$ifdef unix}
  434. Video.ClearScreen;
  435. {$endif unix}
  436. Video.DoneVideo;
  437. Keyboard.DoneKeyboard;
  438. {$endif fpc}
  439. {$ifdef VESA}
  440. DoneVESAScreenModes;
  441. {$endif}
  442. {$ifdef unix}
  443. Keyboard.RestoreStartMode;
  444. {$endif unix}
  445. StreamError:=nil;
  446. {$ifdef DEBUG}
  447. if CloseImmediately then
  448. writeln('Used time is ',getrealtime-StartTime:0:2);
  449. {$endif DEBUG}
  450. END.
  451. {
  452. $Log$
  453. Revision 1.27 2004-12-06 16:23:29 peter
  454. with_gdb -> nodebug
  455. Revision 1.26 2004/11/14 21:45:28 florian
  456. * fixed non working mouse after tools call
  457. * better handling of source/target info
  458. * more info in about dialog
  459. * better info in compiler status dialiog
  460. Revision 1.25 2004/11/08 20:28:25 peter
  461. * Breakpoints are now deleted when removed from source, disabling is
  462. still possible from the breakpoint list
  463. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  464. FV and 1.9.x compilers
  465. * Run directory added to Run menu
  466. * Useless programinfo window removed
  467. Revision 1.24 2004/11/05 00:21:56 peter
  468. version info at startup
  469. Revision 1.23 2003/09/29 14:36:59 peter
  470. * win32 fixed
  471. Revision 1.22 2003/06/04 15:06:14 peter
  472. * histsize increased
  473. Revision 1.21 2003/01/29 00:30:53 pierre
  474. * load CheckMem as first if EXTDEBUG is defined
  475. Revision 1.20 2003/01/28 16:53:47 pierre
  476. * only include fpcygwin if libgdb is linked in
  477. Revision 1.19 2003/01/14 16:24:52 pierre
  478. * only insert win32 resource if IncRes is defined
  479. Revision 1.18 2003/01/07 00:29:13 pierre
  480. + win32 version infos
  481. Revision 1.17 2002/12/12 00:08:09 pierre
  482. Use fpregs unit
  483. Revision 1.16 2002/11/28 12:49:20 pierre
  484. * enable signals catching earlier
  485. Revision 1.15 2002/10/30 22:12:13 pierre
  486. * use ppheap with IDEHEAPTRC conditional
  487. Revision 1.14 2002/10/12 19:43:07 hajny
  488. * missing HasSignal conditionals added (needed for FPC/2)
  489. Revision 1.13 2002/09/10 12:19:14 pierre
  490. * use faster method for loading files by default
  491. Revision 1.12 2002/09/09 06:59:16 pierre
  492. * new debug options added
  493. Revision 1.11 2002/09/07 15:40:41 peter
  494. * old logs removed and tabs fixed
  495. Revision 1.10 2002/09/04 14:07:12 pierre
  496. + Enhance code complete by inserting unit symbols
  497. Revision 1.9 2002/05/29 22:29:42 pierre
  498. Asciitab now in fvision
  499. Revision 1.8 2002/04/12 11:28:55 pierre
  500. + use fpcygwin unit for win32 debug IDE
  501. Revision 1.7 2002/04/12 09:00:01 pierre
  502. * enhance internal error handling
  503. Revision 1.6 2002/03/28 16:32:48 pierre
  504. * clearscrenn at exit for unix
  505. Revision 1.5 2002/03/20 14:56:41 pierre
  506. * correct last commit
  507. Revision 1.4 2002/03/20 14:53:37 pierre
  508. + rescue handlers in main loop
  509. Revision 1.3 2002/01/09 09:46:10 pierre
  510. * fix problems with -S option
  511. }