fp.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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,
  52. {$ifdef FVISION}
  53. FVConsts,
  54. {$else}
  55. Commands,
  56. {$endif}
  57. Drivers,Views,App,Dialogs,
  58. Menus,StdDlg,Validate,
  59. {$ifdef EDITORS}Editors{$else}WEditor,WCEdit{$endif},
  60. {$ifndef FVISION}
  61. ColorSel,
  62. {$endif FVISION}
  63. ASCIITab,
  64. WUtils,WViews,WHTMLScn,WHelp,
  65. FPIDE,FPCalc,FPCompil,FPString,
  66. FPIni,FPViews,FPConst,FPVars,FPUtils,FPHelp,FPSwitch,FPUsrScr,
  67. FPTools,
  68. {$ifndef NODEBUG}
  69. FPDebug,FPRegs,
  70. {$endif}
  71. FPTemplt,FPRedir,FPDesk,
  72. FPCodTmp,FPCodCmp;
  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. {$ifdef GABOR}{$ifdef TP}asm int 3;end;{$endif}{$endif}
  197. if Assigned(Application) then
  198. ErrorBox('Stream error: '+#13+ErrS,nil)
  199. else
  200. writeln('Error: ',ErrS);
  201. end;
  202. end;
  203. procedure DelTempFiles;
  204. begin
  205. DeleteFile(FPOutFileName);
  206. DeleteFile(FPErrFileName);
  207. DeleteFile(GDBOutFileName);
  208. DeleteFile(GDBOutPutFileName);
  209. DeleteFile(GREPOutName);
  210. DeleteFile(GREPErrName);
  211. end;
  212. procedure RegisterIDEObjects;
  213. begin
  214. RegisterApp;
  215. RegisterCodeComplete;
  216. RegisterCodeTemplates;
  217. {$ifndef FVISION}
  218. RegisterColorSel;
  219. {$endif FVISION}
  220. RegisterAsciiTab;
  221. RegisterDialogs;
  222. {$ifdef EDITORS}
  223. RegisterEditors;
  224. {$else}
  225. RegisterWEditor;
  226. RegisterWCEdit;
  227. {$endif}
  228. RegisterFPCalc;
  229. RegisterFPCompile;
  230. RegisterFPTools;
  231. RegisterFPViews;
  232. {$ifndef NODEBUG}
  233. RegisterFPDebugViews;
  234. RegisterFPRegsViews;
  235. {$endif}
  236. RegisterMenus;
  237. RegisterStdDlg;
  238. RegisterSymbols;
  239. RegisterObjects;
  240. RegisterValidate;
  241. RegisterViews;
  242. RegisterWHTMLScan;
  243. RegisterWUtils;
  244. RegisterWViews;
  245. end;
  246. var CanExit : boolean;
  247. SetJmpRes : longint;
  248. StoreExitProc : pointer;
  249. ErrS : String;
  250. P : record
  251. l1 : longint;
  252. s : pstring;
  253. end;
  254. {$ifdef win32}
  255. ShowMouseExe : string;
  256. {$endif win32}
  257. const
  258. ExitIntercepted : boolean = false;
  259. SeenExitCode : longint =0;
  260. SeenErrorAddr : pointer = nil;
  261. UserWantsToGoOn: boolean = false;
  262. procedure InterceptExit;
  263. begin
  264. {$IFDEF HasSignal}
  265. if StopJmpValid then
  266. begin
  267. ExitIntercepted:=true;
  268. SeenExitCode:=ExitCode;
  269. SeenErrorAddr:=ErrorAddr;
  270. LongJmp(StopJmp,1);
  271. end;
  272. {$ENDIF}
  273. end;
  274. BEGIN
  275. {$IFDEF HasSignal}
  276. EnableCatchSignals;
  277. {$ENDIF}
  278. {$ifdef DEV}
  279. HeapLimit:=4096;
  280. {$endif}
  281. writeln('þ Free Pascal IDE Version '+VersionStr);
  282. {$ifdef win32}
  283. Win32ShowMouse;
  284. {$endif win32}
  285. {$ifdef WITH_GDB}
  286. {$ifdef win32}
  287. writeln('Using "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  288. CheckCygwinVersion;
  289. {$endif win32}
  290. {$endif WITH_GDB}
  291. ProcessParams(true);
  292. {$ifdef DEBUG}
  293. StartTime:=getrealtime;
  294. {$endif DEBUG}
  295. InitDirs;
  296. RegisterIDEObjects;
  297. StreamError:=@MyStreamError;
  298. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  299. {$ifdef VESA}
  300. InitVESAScreenModes;
  301. {$endif}
  302. InitRedir;
  303. {$ifndef NODEBUG}
  304. InitBreakpoints;
  305. InitWatches;
  306. {$endif}
  307. InitReservedWords;
  308. InitHelpFiles;
  309. InitSwitches;
  310. InitINIFile;
  311. InitUserScreen;
  312. InitTools;
  313. InitTemplates;
  314. InitCodeTemplates;
  315. InitCodeComplete;
  316. IDEApp.Init;
  317. CheckINIFile;
  318. ReadSwitches(SwitchesPath);
  319. { load all options after init because of open files }
  320. ReadINIFile;
  321. InitDesktopFile;
  322. LoadDesktop;
  323. { Handle Standard Units }
  324. if UseAllUnitsInCodeComplete then
  325. AddAvailableUnitsToCodeComplete(false);
  326. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  327. AddStandardUnitsToCodeComplete;
  328. { why are the screen contents parsed at startup? Gabor
  329. to be able to find location of error in last compilation
  330. from command line PM }
  331. ParseUserScreen;
  332. { Update IDE }
  333. IDEApp.Update;
  334. IDEApp.UpdateMode;
  335. IDEApp.UpdateTarget;
  336. ProcessParams(false);
  337. if ShowReadme then
  338. begin
  339. PutCommand(Application,evCommand,cmShowReadme,nil);
  340. ShowReadme:=false; { do not show next time }
  341. end;
  342. StoreExitProc:=ExitProc;
  343. ExitProc:=@InterceptExit;
  344. repeat
  345. {$IFDEF HasSignal}
  346. SetJmpRes:=setjmp(StopJmp);
  347. StopJmpValid:=true;
  348. {$ENDIF}
  349. UserWantsToGoOn:=false;
  350. if SetJmpRes=0 then
  351. begin
  352. {$ifdef DEBUG}
  353. if not CloseImmediately then
  354. {$endif DEBUG}
  355. IDEApp.Run;
  356. end
  357. else
  358. begin
  359. if (SetJmpRes=1) and ExitIntercepted then
  360. begin
  361. { If ExitProc=@InterceptExit then
  362. ExitProc:=StoreExitProc;}
  363. Str(SeenExitCode,ErrS);
  364. if Assigned(Application) then
  365. begin
  366. P.l1:=SeenExitCode;
  367. ErrS:=hexstr(longint(SeenErrorAddr),8);
  368. P.s:=@ErrS;
  369. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  370. UserWantsToGoOn:=true;
  371. end
  372. else
  373. writeln('Abnormal exit error: ',ErrS);
  374. end
  375. else
  376. begin
  377. Str(SetJmpRes,ErrS);
  378. { Longjmp was called by fpcatch }
  379. if Assigned(Application) then
  380. begin
  381. P.l1:=SetJmpRes;
  382. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  383. UserWantsToGoOn:=true;
  384. end
  385. else
  386. writeln('Signal error: ',ErrS);
  387. end;
  388. end;
  389. if (AutoSaveOptions and asEditorFiles)=0 then
  390. CanExit:=IDEApp.AskSaveAll
  391. else
  392. CanExit:=IDEApp.SaveAll;
  393. {$IFDEF HasSignal}
  394. StopJmpValid:=false;
  395. {$ENDIF}
  396. if (SetJmpRes<>0) then
  397. begin
  398. if (not CanExit) or UserWantsToGoOn then
  399. begin
  400. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  401. CanExit:=true
  402. else
  403. CanExit:=false;
  404. end
  405. else
  406. begin
  407. ErrorBox(leaving_after_error,nil);
  408. end;
  409. end;
  410. until CanExit;
  411. If ExitProc=pointer(@InterceptExit) then
  412. ExitProc:=StoreExitProc;
  413. IDEApp.AutoSave;
  414. DoneDesktopFile;
  415. DelTempFiles;
  416. IDEApp.Done;
  417. WriteSwitches(SwitchesPath);
  418. {$IFDEF HasSignal}
  419. DisableCatchSignals;
  420. {$ENDIF}
  421. DoneCodeComplete;
  422. DoneCodeTemplates;
  423. DoneTemplates;
  424. DoneTools;
  425. DoneUserScreen;
  426. DoneSwitches;
  427. DoneHelpFiles;
  428. DoneHelpFilesTypes;
  429. DoneReservedWords;
  430. DoneToolMessages;
  431. DoneBrowserCol;
  432. {$ifndef NODEBUG}
  433. DoneDebugger;
  434. DoneBreakpoints;
  435. DoneWatches;
  436. {$endif}
  437. {$ifdef fpc}
  438. {$ifdef unix}
  439. Video.ClearScreen;
  440. {$endif unix}
  441. Video.DoneVideo;
  442. Keyboard.DoneKeyboard;
  443. {$endif fpc}
  444. {$ifdef VESA}
  445. DoneVESAScreenModes;
  446. {$endif}
  447. {$ifdef unix}
  448. Keyboard.RestoreStartMode;
  449. {$endif unix}
  450. StreamError:=nil;
  451. {$ifdef DEBUG}
  452. if CloseImmediately then
  453. writeln('Used time is ',getrealtime-StartTime:0:2);
  454. {$endif DEBUG}
  455. END.
  456. {
  457. $Log$
  458. Revision 1.21 2003-01-29 00:30:53 pierre
  459. * load CheckMem as first if EXTDEBUG is defined
  460. Revision 1.20 2003/01/28 16:53:47 pierre
  461. * only include fpcygwin if libgdb is linked in
  462. Revision 1.19 2003/01/14 16:24:52 pierre
  463. * only insert win32 resource if IncRes is defined
  464. Revision 1.18 2003/01/07 00:29:13 pierre
  465. + win32 version infos
  466. Revision 1.17 2002/12/12 00:08:09 pierre
  467. Use fpregs unit
  468. Revision 1.16 2002/11/28 12:49:20 pierre
  469. * enable signals catching earlier
  470. Revision 1.15 2002/10/30 22:12:13 pierre
  471. * use ppheap with IDEHEAPTRC conditional
  472. Revision 1.14 2002/10/12 19:43:07 hajny
  473. * missing HasSignal conditionals added (needed for FPC/2)
  474. Revision 1.13 2002/09/10 12:19:14 pierre
  475. * use faster method for loading files by default
  476. Revision 1.12 2002/09/09 06:59:16 pierre
  477. * new debug options added
  478. Revision 1.11 2002/09/07 15:40:41 peter
  479. * old logs removed and tabs fixed
  480. Revision 1.10 2002/09/04 14:07:12 pierre
  481. + Enhance code complete by inserting unit symbols
  482. Revision 1.9 2002/05/29 22:29:42 pierre
  483. Asciitab now in fvision
  484. Revision 1.8 2002/04/12 11:28:55 pierre
  485. + use fpcygwin unit for win32 debug IDE
  486. Revision 1.7 2002/04/12 09:00:01 pierre
  487. * enhance internal error handling
  488. Revision 1.6 2002/03/28 16:32:48 pierre
  489. * clearscrenn at exit for unix
  490. Revision 1.5 2002/03/20 14:56:41 pierre
  491. * correct last commit
  492. Revision 1.4 2002/03/20 14:53:37 pierre
  493. + rescue handlers in main loop
  494. Revision 1.3 2002/01/09 09:46:10 pierre
  495. * fix problems with -S option
  496. }