fp.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. {$ifdef fpc}
  73. Const
  74. DummyMouseDriver : TMouseDriver = (
  75. useDefaultQueue : true;
  76. InitDriver : nil;
  77. DoneDriver : nil;
  78. DetectMouse : nil;
  79. ShowMouse : nil;
  80. HideMouse : nil;
  81. GetMouseX : nil;
  82. GetMouseY : nil;
  83. GetMouseButtons : nil;
  84. SetMouseXY : nil;
  85. GetMouseEvent : nil;
  86. PollMouseEvent : nil;
  87. PutMouseEvent : nil;
  88. );
  89. {$endif fpc}
  90. {$ifdef DEBUG}
  91. const
  92. CloseImmediately : boolean = false;
  93. var
  94. StartTime : real;
  95. function getrealtime : real;
  96. var
  97. h,m,s,s100 : word;
  98. begin
  99. gettime(h,m,s,s100);
  100. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  101. end;
  102. {$endif DEBUG}
  103. procedure ProcessParams(BeforeINI: boolean);
  104. function IsSwitch(const Param: string): boolean;
  105. begin
  106. IsSwitch:=(Param<>'') and (Param[1]<>DirSep) { <- allow UNIX root-relative paths }
  107. and (Param[1] in ['-','/']); { <- but still accept dos switch char, eg. '/' }
  108. end;
  109. var I: Sw_integer;
  110. Param: string;
  111. begin
  112. for I:=1 to ParamCount do
  113. begin
  114. Param:=System.ParamStr(I);
  115. if IsSwitch(Param) then
  116. begin
  117. Param:=copy(Param,2,255);
  118. if Param<>'' then
  119. if UpcaseStr(copy(Param,1,2))='HM' then
  120. { HeapMonitor }
  121. begin
  122. if (copy(Param,3,1)='+') or (copy(Param,3,1)='') then
  123. StartupOptions:=StartupOptions or soHeapMonitor
  124. else
  125. if (copy(Param,3,1)='-') then
  126. StartupOptions:=StartupOptions and not soHeapMonitor;
  127. end else
  128. {$ifdef go32v2}
  129. if UpcaseStr(Param)='NOLFN' then
  130. begin
  131. LFNSupport:=false;
  132. end else
  133. {$endif go32v2}
  134. if UpcaseStr(Param)='README' then
  135. begin
  136. ShowReadme:=true;
  137. end else
  138. case Upcase(Param[1]) of
  139. 'C' : { custom config file (BP compatiblity) }
  140. if BeforeINI then
  141. begin
  142. if (length(Param)>=1) and (Param[1] in['=',':']) then
  143. Delete(Param,1,1); { eat separator }
  144. IniFileName:=Param;
  145. end;
  146. 'R' : { enter the directory last exited from (BP comp.) }
  147. begin
  148. Param:=copy(Param,2,255);
  149. if (Param='') or (Param='+') then
  150. StartupOptions:=StartupOptions or soReturnToLastDir
  151. else
  152. if (Param='-') then
  153. StartupOptions:=StartupOptions and (not soReturnToLastDir);
  154. end;
  155. 'S' :
  156. if Length(Param)=1 then
  157. begin
  158. UseMouse:=false;
  159. {$ifdef fpc}
  160. DoneMouse;
  161. SetMouseDriver(DummyMouseDriver);
  162. {$endif fpc}
  163. ButtonCount:=0;
  164. end;
  165. {$ifdef fpc}
  166. 'F' :
  167. if Length(Param)=1 then
  168. NoExtendedFrame:=true;
  169. {$ifdef Unix}
  170. 'T' : DebuggeeTTY:=Copy(Param,2,High(Param));
  171. {$endif Unix}
  172. { 'M' : TryToMaximizeScreen:=true;}
  173. {$endif fpc}
  174. {$ifdef DEBUG}
  175. 'Z' : UseOldBufStreamMethod:=true;
  176. 'X' : CloseImmediately:=true;
  177. {$endif DEBUG}
  178. end;
  179. end
  180. else
  181. if not BeforeINI then
  182. TryToOpenFile(nil,Param,0,0,{false}true);
  183. end;
  184. end;
  185. Procedure MyStreamError(Var S: TStream); {$ifndef FPC}far;{$endif}
  186. var ErrS: string;
  187. begin
  188. case S.Status of
  189. stGetError : ErrS:='Get of unregistered object type';
  190. stPutError : ErrS:='Put of unregistered object type';
  191. else ErrS:='';
  192. end;
  193. if ErrS<>'' then
  194. begin
  195. if Assigned(Application) then
  196. ErrorBox('Stream error: '+#13+ErrS,nil)
  197. else
  198. writeln('Error: ',ErrS);
  199. end;
  200. end;
  201. procedure DelTempFiles;
  202. begin
  203. DeleteFile(FPOutFileName);
  204. DeleteFile(FPErrFileName);
  205. DeleteFile(GDBOutFileName);
  206. DeleteFile(GDBOutPutFileName);
  207. DeleteFile(GREPOutName);
  208. DeleteFile(GREPErrName);
  209. end;
  210. procedure RegisterIDEObjects;
  211. begin
  212. RegisterApp;
  213. RegisterCodeComplete;
  214. RegisterCodeTemplates;
  215. {$ifdef COLORSEL}
  216. RegisterColorSel;
  217. {$endif COLORSEL}
  218. RegisterAsciiTab;
  219. RegisterDialogs;
  220. RegisterWEditor;
  221. RegisterWCEdit;
  222. RegisterFPCalc;
  223. RegisterFPCompile;
  224. RegisterFPTools;
  225. RegisterFPViews;
  226. {$ifndef NODEBUG}
  227. RegisterFPDebugViews;
  228. RegisterFPRegsViews;
  229. {$endif}
  230. RegisterMenus;
  231. RegisterStdDlg;
  232. RegisterSymbols;
  233. RegisterObjects;
  234. RegisterValidate;
  235. RegisterViews;
  236. RegisterWHTMLScan;
  237. RegisterWUtils;
  238. RegisterWViews;
  239. end;
  240. var CanExit : boolean;
  241. SetJmpRes : longint;
  242. StoreExitProc : pointer;
  243. ErrS : String;
  244. P : record
  245. l1 : longint;
  246. s : pstring;
  247. end;
  248. {$ifdef win32}
  249. ShowMouseExe : string;
  250. {$endif win32}
  251. const
  252. ExitIntercepted : boolean = false;
  253. SeenExitCode : longint =0;
  254. SeenErrorAddr : pointer = nil;
  255. UserWantsToGoOn: boolean = false;
  256. procedure InterceptExit;
  257. begin
  258. {$IFDEF HasSignal}
  259. if StopJmpValid then
  260. begin
  261. ExitIntercepted:=true;
  262. SeenExitCode:=ExitCode;
  263. SeenErrorAddr:=ErrorAddr;
  264. LongJmp(StopJmp,1);
  265. end;
  266. {$ENDIF}
  267. end;
  268. BEGIN
  269. {$IFDEF HasSignal}
  270. EnableCatchSignals;
  271. {$ENDIF}
  272. {$ifdef DEV}
  273. HeapLimit:=4096;
  274. {$endif}
  275. HistorySize:=16384;
  276. { Startup info }
  277. writeln('þ Free Pascal IDE Version '+VersionStr+' ['+{$i %date%}+']');
  278. writeln('þ Compiler Version '+Version_String);
  279. {$ifdef WITH_GDB}
  280. writeln('þ GBD Version '+GDBVersion);
  281. {$ifdef win32}
  282. writeln('þ Cygwin "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  283. CheckCygwinVersion;
  284. {$endif win32}
  285. {$endif WITH_GDB}
  286. ProcessParams(true);
  287. {$ifdef DEBUG}
  288. StartTime:=getrealtime;
  289. {$endif DEBUG}
  290. InitDirs;
  291. RegisterIDEObjects;
  292. StreamError:=@MyStreamError;
  293. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  294. {$ifdef VESA}
  295. InitVESAScreenModes;
  296. {$endif}
  297. InitRedir;
  298. {$ifndef NODEBUG}
  299. InitBreakpoints;
  300. InitWatches;
  301. {$endif}
  302. InitReservedWords;
  303. InitHelpFiles;
  304. InitSwitches;
  305. InitINIFile;
  306. InitUserScreen;
  307. InitTools;
  308. InitTemplates;
  309. InitCodeTemplates;
  310. InitCodeComplete;
  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.25 2004-11-08 20:28:25 peter
  454. * Breakpoints are now deleted when removed from source, disabling is
  455. still possible from the breakpoint list
  456. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  457. FV and 1.9.x compilers
  458. * Run directory added to Run menu
  459. * Useless programinfo window removed
  460. Revision 1.24 2004/11/05 00:21:56 peter
  461. version info at startup
  462. Revision 1.23 2003/09/29 14:36:59 peter
  463. * win32 fixed
  464. Revision 1.22 2003/06/04 15:06:14 peter
  465. * histsize increased
  466. Revision 1.21 2003/01/29 00:30:53 pierre
  467. * load CheckMem as first if EXTDEBUG is defined
  468. Revision 1.20 2003/01/28 16:53:47 pierre
  469. * only include fpcygwin if libgdb is linked in
  470. Revision 1.19 2003/01/14 16:24:52 pierre
  471. * only insert win32 resource if IncRes is defined
  472. Revision 1.18 2003/01/07 00:29:13 pierre
  473. + win32 version infos
  474. Revision 1.17 2002/12/12 00:08:09 pierre
  475. Use fpregs unit
  476. Revision 1.16 2002/11/28 12:49:20 pierre
  477. * enable signals catching earlier
  478. Revision 1.15 2002/10/30 22:12:13 pierre
  479. * use ppheap with IDEHEAPTRC conditional
  480. Revision 1.14 2002/10/12 19:43:07 hajny
  481. * missing HasSignal conditionals added (needed for FPC/2)
  482. Revision 1.13 2002/09/10 12:19:14 pierre
  483. * use faster method for loading files by default
  484. Revision 1.12 2002/09/09 06:59:16 pierre
  485. * new debug options added
  486. Revision 1.11 2002/09/07 15:40:41 peter
  487. * old logs removed and tabs fixed
  488. Revision 1.10 2002/09/04 14:07:12 pierre
  489. + Enhance code complete by inserting unit symbols
  490. Revision 1.9 2002/05/29 22:29:42 pierre
  491. Asciitab now in fvision
  492. Revision 1.8 2002/04/12 11:28:55 pierre
  493. + use fpcygwin unit for win32 debug IDE
  494. Revision 1.7 2002/04/12 09:00:01 pierre
  495. * enhance internal error handling
  496. Revision 1.6 2002/03/28 16:32:48 pierre
  497. * clearscrenn at exit for unix
  498. Revision 1.5 2002/03/20 14:56:41 pierre
  499. * correct last commit
  500. Revision 1.4 2002/03/20 14:53:37 pierre
  501. + rescue handlers in main loop
  502. Revision 1.3 2002/01/09 09:46:10 pierre
  503. * fix problems with -S option
  504. }