fp.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998-2000 by Berczi Gabor
  4. Main program of the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program FP;
  12. {$ifdef Windows}
  13. { some windows versions, namely at least XP x64 don't like if the IDE stack
  14. is too big }
  15. {$maxstacksize 3000000}
  16. {$ifdef IncRes}
  17. {$R fpw32t.rc}
  18. {$R fpw32ico.rc}
  19. {$endif IncRes}
  20. {$endif Windows}
  21. {$I globdir.inc}
  22. (**********************************************************************)
  23. (* CONDITIONAL DEFINES *)
  24. (* - NODEBUG No Debugging support *)
  25. (* - i386 Target is an i386 IDE *)
  26. (**********************************************************************)
  27. uses
  28. {$ifdef Windows}
  29. windows,
  30. {$endif Windows}
  31. {$ifndef NODEBUG}
  32. {$ifdef Windows}
  33. {$ifdef USE_MINGW_GDB}
  34. fpmingw,
  35. {$else}
  36. fpcygwin,
  37. {$endif}
  38. {$endif Windows}
  39. {$endif NODEBUG}
  40. {$ifdef IDEHeapTrc}
  41. PPheap,
  42. {$endif IDEHeapTrc}
  43. {$ifdef Use_DBGHEAP}
  44. dbgheap,
  45. {$endif Use_DBGHEAP}
  46. {$ifdef go32v2}
  47. dpmiexcp,
  48. {$endif go32v2}
  49. keyboard,video,mouse,
  50. {$ifdef HasSignal}
  51. fpcatch,
  52. {$endif HasSignal}
  53. Dos,Objects,
  54. BrowCol,Version,
  55. {$ifndef NODEBUG}
  56. gdbint,
  57. {$endif NODEBUG}
  58. FVConsts,
  59. Drivers,Views,App,Dialogs,HistList,
  60. Menus,StdDlg,Validate,
  61. WEditor,WCEdit,
  62. {$ifdef COLORSEL}
  63. ColorSel,
  64. {$endif COLORSEL}
  65. ASCIITab,
  66. WUtils,WViews,WHTMLScn,WHelp,
  67. FPIDE,FPCalc,FPCompil,
  68. FPIni,FPViews,FPConst,FPVars,FPUtils,FPHelp,FPSwitch,FPUsrScr,
  69. FPTools,
  70. {$ifndef NODEBUG}
  71. FPDebug,FPRegs,
  72. {$endif}
  73. FPTemplt,FPRedir,FPDesk,
  74. FPCodTmp,FPCodCmp,
  75. systems,globtype,globals;
  76. Const
  77. DummyMouseDriver : TMouseDriver = (
  78. useDefaultQueue : true;
  79. InitDriver : nil;
  80. DoneDriver : nil;
  81. DetectMouse : nil;
  82. ShowMouse : nil;
  83. HideMouse : nil;
  84. GetMouseX : nil;
  85. GetMouseY : nil;
  86. GetMouseButtons : nil;
  87. SetMouseXY : nil;
  88. GetMouseEvent : nil;
  89. PollMouseEvent : nil;
  90. PutMouseEvent : nil;
  91. );
  92. {$ifdef useresstrings}
  93. resourcestring
  94. {$else}
  95. const
  96. {$endif}
  97. { caught signals or abnormal exits }
  98. { Debugger messages and status hints }
  99. error_programexitedwitherror = #3'Program generated a RTE %d'#13+
  100. #3'at address $%s.'#13+
  101. #3'Save your sources and restart the IDE.';
  102. error_programexitedwithsignal = #3'Program generated a signal %d.'#13+
  103. #3'Save your sources and restart the IDE.';
  104. continue_despite_error = #3'The IDE generated an internal error'#13+
  105. #3'Do you really want to continue?'#13+
  106. #3'The IDE could be in an unstable state.';
  107. leaving_after_error = #3'The IDE generated an internal error'#13+
  108. #3'and will now be closed.';
  109. {$ifdef DEBUG}
  110. const
  111. CloseImmediately : boolean = false;
  112. var
  113. StartTime : real;
  114. function getrealtime : real;
  115. var
  116. h,m,s,s100 : word;
  117. begin
  118. gettime(h,m,s,s100);
  119. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  120. end;
  121. {$endif DEBUG}
  122. procedure ProcessParams(BeforeINI: boolean);
  123. function IsSwitch(const Param: string): boolean;
  124. begin
  125. IsSwitch:=(Param<>'') and (Param[1]<>DirSep) { <- allow UNIX root-relative paths }
  126. and (Param[1] in ['-','/']); { <- but still accept dos switch char, eg. '/' }
  127. end;
  128. var I: Sw_integer;
  129. Param: string;
  130. begin
  131. for I:=1 to ParamCount do
  132. begin
  133. Param:=System.ParamStr(I);
  134. if IsSwitch(Param) then
  135. begin
  136. Param:=copy(Param,2,255);
  137. if Param<>'' then
  138. if UpcaseStr(copy(Param,1,2))='HM' then
  139. { HeapMonitor }
  140. begin
  141. if (copy(Param,3,1)='+') or (copy(Param,3,1)='') then
  142. StartupOptions:=StartupOptions or soHeapMonitor
  143. else
  144. if (copy(Param,3,1)='-') then
  145. StartupOptions:=StartupOptions and not soHeapMonitor;
  146. end else
  147. {$ifdef go32v2}
  148. if UpcaseStr(Param)='NOLFN' then
  149. begin
  150. LFNSupport:=false;
  151. end else
  152. {$endif go32v2}
  153. if UpcaseStr(Param)='README' then
  154. begin
  155. ShowReadme:=true;
  156. end else
  157. case Upcase(Param[1]) of
  158. 'C' : { custom config file (BP compatiblity) }
  159. if BeforeINI then
  160. begin
  161. if (length(Param)>=1) and (Param[1] in['=',':']) then
  162. Delete(Param,1,1); { eat separator }
  163. IniFileName:=Param;
  164. end;
  165. 'R' : { enter the directory last exited from (BP comp.) }
  166. begin
  167. Param:=copy(Param,2,255);
  168. if (Param='') or (Param='+') then
  169. StartupOptions:=StartupOptions or soReturnToLastDir
  170. else
  171. if (Param='-') then
  172. StartupOptions:=StartupOptions and (not soReturnToLastDir);
  173. end;
  174. 'S' :
  175. if Length(Param)=1 then
  176. begin
  177. UseMouse:=false;
  178. DoneMouse;
  179. SetMouseDriver(DummyMouseDriver);
  180. ButtonCount:=0;
  181. end;
  182. { 'F' :
  183. if Length(Param)=1 then
  184. NoExtendedFrame:=true;}
  185. {$ifdef Unix}
  186. 'T' : DebuggeeTTY:=Copy(Param,2,High(Param));
  187. {$endif Unix}
  188. { 'M' : TryToMaximizeScreen:=true;}
  189. {$ifdef DEBUG}
  190. 'Z' : UseOldBufStreamMethod:=true;
  191. 'X' : CloseImmediately:=true;
  192. {$endif DEBUG}
  193. end;
  194. end
  195. else
  196. if not BeforeINI then
  197. TryToOpenFileMulti(nil,Param,0,0,{false}true);
  198. end;
  199. end;
  200. Procedure MyStreamError(Var S: TStream);
  201. var ErrS: string;
  202. begin
  203. case S.Status of
  204. stGetError : ErrS:='Get of unregistered object type';
  205. stPutError : ErrS:='Put of unregistered object type';
  206. else ErrS:='';
  207. end;
  208. if ErrS<>'' then
  209. begin
  210. if (application<>nil) and (ideapp.displaymode=dmIDE) then
  211. ErrorBox('Stream error: '+#13+ErrS,nil)
  212. else
  213. writeln('Error: ',ErrS);
  214. end;
  215. end;
  216. procedure DelTempFiles;
  217. begin
  218. DeleteFile(FPOutFileName);
  219. DeleteFile(FPErrFileName);
  220. DeleteFile(GDBOutFileName);
  221. DeleteFile(GDBOutPutFileName);
  222. DeleteFile(GREPOutName);
  223. DeleteFile(GREPErrName);
  224. end;
  225. procedure RegisterIDEObjects;
  226. begin
  227. RegisterApp;
  228. RegisterCodeComplete;
  229. RegisterCodeTemplates;
  230. {$ifdef COLORSEL}
  231. RegisterColorSel;
  232. {$endif COLORSEL}
  233. RegisterAsciiTab;
  234. RegisterDialogs;
  235. RegisterWEditor;
  236. RegisterWCEdit;
  237. RegisterFPCalc;
  238. RegisterFPCompile;
  239. RegisterFPTools;
  240. RegisterFPViews;
  241. {$ifndef NODEBUG}
  242. RegisterFPDebugViews;
  243. RegisterFPRegsViews;
  244. {$endif}
  245. RegisterMenus;
  246. RegisterStdDlg;
  247. RegisterSymbols;
  248. RegisterObjects;
  249. RegisterValidate;
  250. RegisterViews;
  251. RegisterWHTMLScan;
  252. RegisterWUtils;
  253. RegisterWViews;
  254. end;
  255. var CanExit : boolean;
  256. SetJmpRes : longint;
  257. StoreExitProc : pointer;
  258. ErrS : String;
  259. P : record
  260. l1 : longint;
  261. s : pstring;
  262. end;
  263. const
  264. ExitIntercepted : boolean = false;
  265. SeenExitCode : longint =0;
  266. SeenErrorAddr : pointer = nil;
  267. UserWantsToGoOn: boolean = false;
  268. procedure InterceptExit;
  269. begin
  270. {$IFDEF HasSignal}
  271. if StopJmpValid then
  272. begin
  273. ExitIntercepted:=true;
  274. SeenExitCode:=ExitCode;
  275. SeenErrorAddr:=ErrorAddr;
  276. LongJmp(StopJmp,1);
  277. end;
  278. {$ENDIF}
  279. end;
  280. procedure InitCompilerSwitches;
  281. begin
  282. default_settings.globalswitches:=[cs_check_unit_name];
  283. default_settings.moduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  284. default_settings.localswitches:=[cs_typed_const_writable];
  285. end;
  286. {The square bullet needs an MS-DOS code page. On Unix it is for sure the code
  287. page is not available before video is initialized. (And only in certain
  288. circumstances after that, so, use a plain ascii character as bullet on Unix.)}
  289. {$if defined(unix) or defined(amiga) or defined(morphos)}
  290. const bullet='*';
  291. {$else}
  292. const bullet='þ';
  293. {$endif}
  294. BEGIN
  295. {$IFDEF HasSignal}
  296. EnableCatchSignals;
  297. {$ENDIF}
  298. {$ifdef DEV}
  299. HeapLimit:=4096;
  300. {$endif}
  301. HistorySize:=16384;
  302. { Startup info }
  303. writeln(bullet+' Free Pascal IDE Version '+VersionStr+' ['+{$i %date%}+']');
  304. writeln(bullet+' Compiler Version '+Full_Version_String);
  305. {$ifndef NODEBUG}
  306. writeln(bullet+' GDB Version '+GDBVersion);
  307. {$ifdef Windows}
  308. {$ifndef USE_MINGW_GDB}
  309. writeln(bullet+' Cygwin "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  310. CheckCygwinVersion;
  311. {$endif}
  312. {$endif Windows}
  313. {$endif NODEBUG}
  314. ProcessParams(true);
  315. {$ifdef DEBUG}
  316. StartTime:=getrealtime;
  317. {$endif DEBUG}
  318. InitDirs;
  319. RegisterIDEObjects;
  320. StreamError:=@MyStreamError;
  321. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  322. if LocateFile(INIFileName)<>'' then
  323. writeln(bullet+' Using configuration files from: ',DirOf(LocateFile(INIFileName)));
  324. InitCompilerSwitches;
  325. {$ifdef VESA}
  326. InitVESAScreenModes;
  327. {$endif}
  328. InitRedir;
  329. {$ifndef NODEBUG}
  330. InitBreakpoints;
  331. InitWatches;
  332. {$endif}
  333. InitReservedWords;
  334. InitHelpFiles;
  335. InitSwitches;
  336. InitINIFile;
  337. InitUserScreen;
  338. InitTools;
  339. InitTemplates;
  340. InitCodeTemplates;
  341. InitCodeComplete;
  342. { init target information etc. }
  343. InitSystems;
  344. IDEApp.Init;
  345. CheckINIFile;
  346. ReadSwitches(SwitchesPath);
  347. { load all options after init because of open files }
  348. ReadINIFile;
  349. InitDesktopFile;
  350. LoadDesktop;
  351. {Menubar might be changed because of loading INI file.}
  352. IDEapp.reload_menubar;
  353. { Handle Standard Units }
  354. if UseAllUnitsInCodeComplete then
  355. AddAvailableUnitsToCodeComplete(false);
  356. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  357. AddStandardUnitsToCodeComplete;
  358. { why are the screen contents parsed at startup? Gabor
  359. to be able to find location of error in last compilation
  360. from command line PM }
  361. ParseUserScreen;
  362. { Update IDE }
  363. IDEApp.Update;
  364. IDEApp.UpdateMode;
  365. IDEApp.UpdateTarget;
  366. ProcessParams(false);
  367. if ShowReadme then
  368. begin
  369. PutCommand(Application,evCommand,cmShowReadme,nil);
  370. ShowReadme:=false; { do not show next time }
  371. end;
  372. StoreExitProc:=ExitProc;
  373. ExitProc:=@InterceptExit;
  374. repeat
  375. {$IFDEF HasSignal}
  376. SetJmpRes:=setjmp(StopJmp);
  377. StopJmpValid:=true;
  378. {$ENDIF}
  379. UserWantsToGoOn:=false;
  380. if SetJmpRes=0 then
  381. begin
  382. {$ifdef DEBUG}
  383. if not CloseImmediately then
  384. {$endif DEBUG}
  385. IDEApp.Run;
  386. end
  387. else
  388. begin
  389. if (SetJmpRes=1) and ExitIntercepted then
  390. begin
  391. { If ExitProc=@InterceptExit then
  392. ExitProc:=StoreExitProc;}
  393. Str(SeenExitCode,ErrS);
  394. if (application<>nil) and (ideapp.displaymode=dmIDE) then
  395. begin
  396. P.l1:=SeenExitCode;
  397. ErrS:=hexstr(PtrUInt(SeenErrorAddr),sizeof(PtrUInt)*2);
  398. P.s:=@ErrS;
  399. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  400. UserWantsToGoOn:=true;
  401. end
  402. else
  403. writeln('Abnormal exit error: ',ErrS);
  404. end
  405. else
  406. begin
  407. Str(SetJmpRes,ErrS);
  408. { Longjmp was called by fpcatch }
  409. if (application<>nil) and (ideapp.displaymode=dmIDE) then
  410. begin
  411. P.l1:=SetJmpRes;
  412. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  413. UserWantsToGoOn:=true;
  414. end
  415. else
  416. writeln('Signal error: ',ErrS);
  417. end;
  418. if ideapp.displaymode=dmUser then
  419. begin
  420. writeln('Fatal exception occured while in user screen mode. File save message boxes');
  421. writeln('cannot be displayed. We are sorry, but need to terminate now.');
  422. halt(255);
  423. end;
  424. end;
  425. if (AutoSaveOptions and asEditorFiles)=0 then
  426. CanExit:=IDEApp.AskSaveAll
  427. else
  428. CanExit:=IDEApp.SaveAll;
  429. {$IFDEF HasSignal}
  430. StopJmpValid:=false;
  431. {$ENDIF}
  432. if (SetJmpRes<>0) then
  433. begin
  434. if (not CanExit) or UserWantsToGoOn then
  435. begin
  436. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  437. CanExit:=true
  438. else
  439. CanExit:=false;
  440. end
  441. else
  442. begin
  443. ErrorBox(leaving_after_error,nil);
  444. end;
  445. end;
  446. until CanExit;
  447. If ExitProc=pointer(@InterceptExit) then
  448. ExitProc:=StoreExitProc;
  449. IDEApp.AutoSave;
  450. DoneDesktopFile;
  451. DelTempFiles;
  452. IDEApp.Done;
  453. WriteSwitches(SwitchesPath);
  454. {$IFDEF HasSignal}
  455. DisableCatchSignals;
  456. {$ENDIF}
  457. DoneCodeComplete;
  458. DoneCodeTemplates;
  459. DoneTemplates;
  460. DoneTools;
  461. DoneUserScreen;
  462. DoneSwitches;
  463. DoneHelpFiles;
  464. DoneHelpFilesTypes;
  465. DoneReservedWords;
  466. DoneToolMessages;
  467. DoneBrowserCol;
  468. {$ifndef NODEBUG}
  469. DoneDebugger;
  470. DoneBreakpoints;
  471. DoneWatches;
  472. {$endif}
  473. {$ifdef unix}
  474. Video.ClearScreen;
  475. {$endif unix}
  476. { Video.DoneVideo;
  477. Keyboard.DoneKeyboard;}
  478. {$ifdef VESA}
  479. DoneVESAScreenModes;
  480. {$endif}
  481. {$if defined(unix)}
  482. Keyboard.RestoreStartMode;
  483. {$endif defined(unix)}
  484. {$if defined(windows)}
  485. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)),StartupConsoleMode);
  486. {$endif defined(windows)}
  487. StreamError:=nil;
  488. {$ifdef DEBUG}
  489. if CloseImmediately then
  490. writeln('Used time is ',getrealtime-StartTime:0:2);
  491. {$endif DEBUG}
  492. END.