fp.pas 13 KB

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