fp.pas 13 KB

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