fp.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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,HistList,
  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. HistorySize:=16384;
  282. writeln('þ Free Pascal IDE Version '+VersionStr);
  283. {$ifdef win32}
  284. // Win32ShowMouse;
  285. {$endif win32}
  286. {$ifdef WITH_GDB}
  287. {$ifdef win32}
  288. writeln('Using "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  289. CheckCygwinVersion;
  290. {$endif win32}
  291. {$endif WITH_GDB}
  292. ProcessParams(true);
  293. {$ifdef DEBUG}
  294. StartTime:=getrealtime;
  295. {$endif DEBUG}
  296. InitDirs;
  297. RegisterIDEObjects;
  298. StreamError:=@MyStreamError;
  299. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  300. {$ifdef VESA}
  301. InitVESAScreenModes;
  302. {$endif}
  303. InitRedir;
  304. {$ifndef NODEBUG}
  305. InitBreakpoints;
  306. InitWatches;
  307. {$endif}
  308. InitReservedWords;
  309. InitHelpFiles;
  310. InitSwitches;
  311. InitINIFile;
  312. InitUserScreen;
  313. InitTools;
  314. InitTemplates;
  315. InitCodeTemplates;
  316. InitCodeComplete;
  317. IDEApp.Init;
  318. CheckINIFile;
  319. ReadSwitches(SwitchesPath);
  320. { load all options after init because of open files }
  321. ReadINIFile;
  322. InitDesktopFile;
  323. LoadDesktop;
  324. { Handle Standard Units }
  325. if UseAllUnitsInCodeComplete then
  326. AddAvailableUnitsToCodeComplete(false);
  327. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  328. AddStandardUnitsToCodeComplete;
  329. { why are the screen contents parsed at startup? Gabor
  330. to be able to find location of error in last compilation
  331. from command line PM }
  332. ParseUserScreen;
  333. { Update IDE }
  334. IDEApp.Update;
  335. IDEApp.UpdateMode;
  336. IDEApp.UpdateTarget;
  337. ProcessParams(false);
  338. if ShowReadme then
  339. begin
  340. PutCommand(Application,evCommand,cmShowReadme,nil);
  341. ShowReadme:=false; { do not show next time }
  342. end;
  343. StoreExitProc:=ExitProc;
  344. ExitProc:=@InterceptExit;
  345. repeat
  346. {$IFDEF HasSignal}
  347. SetJmpRes:=setjmp(StopJmp);
  348. StopJmpValid:=true;
  349. {$ENDIF}
  350. UserWantsToGoOn:=false;
  351. if SetJmpRes=0 then
  352. begin
  353. {$ifdef DEBUG}
  354. if not CloseImmediately then
  355. {$endif DEBUG}
  356. IDEApp.Run;
  357. end
  358. else
  359. begin
  360. if (SetJmpRes=1) and ExitIntercepted then
  361. begin
  362. { If ExitProc=@InterceptExit then
  363. ExitProc:=StoreExitProc;}
  364. Str(SeenExitCode,ErrS);
  365. if Assigned(Application) then
  366. begin
  367. P.l1:=SeenExitCode;
  368. ErrS:=hexstr(longint(SeenErrorAddr),8);
  369. P.s:=@ErrS;
  370. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  371. UserWantsToGoOn:=true;
  372. end
  373. else
  374. writeln('Abnormal exit error: ',ErrS);
  375. end
  376. else
  377. begin
  378. Str(SetJmpRes,ErrS);
  379. { Longjmp was called by fpcatch }
  380. if Assigned(Application) then
  381. begin
  382. P.l1:=SetJmpRes;
  383. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  384. UserWantsToGoOn:=true;
  385. end
  386. else
  387. writeln('Signal error: ',ErrS);
  388. end;
  389. end;
  390. if (AutoSaveOptions and asEditorFiles)=0 then
  391. CanExit:=IDEApp.AskSaveAll
  392. else
  393. CanExit:=IDEApp.SaveAll;
  394. {$IFDEF HasSignal}
  395. StopJmpValid:=false;
  396. {$ENDIF}
  397. if (SetJmpRes<>0) then
  398. begin
  399. if (not CanExit) or UserWantsToGoOn then
  400. begin
  401. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  402. CanExit:=true
  403. else
  404. CanExit:=false;
  405. end
  406. else
  407. begin
  408. ErrorBox(leaving_after_error,nil);
  409. end;
  410. end;
  411. until CanExit;
  412. If ExitProc=pointer(@InterceptExit) then
  413. ExitProc:=StoreExitProc;
  414. IDEApp.AutoSave;
  415. DoneDesktopFile;
  416. DelTempFiles;
  417. IDEApp.Done;
  418. WriteSwitches(SwitchesPath);
  419. {$IFDEF HasSignal}
  420. DisableCatchSignals;
  421. {$ENDIF}
  422. DoneCodeComplete;
  423. DoneCodeTemplates;
  424. DoneTemplates;
  425. DoneTools;
  426. DoneUserScreen;
  427. DoneSwitches;
  428. DoneHelpFiles;
  429. DoneHelpFilesTypes;
  430. DoneReservedWords;
  431. DoneToolMessages;
  432. DoneBrowserCol;
  433. {$ifndef NODEBUG}
  434. DoneDebugger;
  435. DoneBreakpoints;
  436. DoneWatches;
  437. {$endif}
  438. {$ifdef fpc}
  439. {$ifdef unix}
  440. Video.ClearScreen;
  441. {$endif unix}
  442. Video.DoneVideo;
  443. Keyboard.DoneKeyboard;
  444. {$endif fpc}
  445. {$ifdef VESA}
  446. DoneVESAScreenModes;
  447. {$endif}
  448. {$ifdef unix}
  449. Keyboard.RestoreStartMode;
  450. {$endif unix}
  451. StreamError:=nil;
  452. {$ifdef DEBUG}
  453. if CloseImmediately then
  454. writeln('Used time is ',getrealtime-StartTime:0:2);
  455. {$endif DEBUG}
  456. END.
  457. {
  458. $Log$
  459. Revision 1.23 2003-09-29 14:36:59 peter
  460. * win32 fixed
  461. Revision 1.22 2003/06/04 15:06:14 peter
  462. * histsize increased
  463. Revision 1.21 2003/01/29 00:30:53 pierre
  464. * load CheckMem as first if EXTDEBUG is defined
  465. Revision 1.20 2003/01/28 16:53:47 pierre
  466. * only include fpcygwin if libgdb is linked in
  467. Revision 1.19 2003/01/14 16:24:52 pierre
  468. * only insert win32 resource if IncRes is defined
  469. Revision 1.18 2003/01/07 00:29:13 pierre
  470. + win32 version infos
  471. Revision 1.17 2002/12/12 00:08:09 pierre
  472. Use fpregs unit
  473. Revision 1.16 2002/11/28 12:49:20 pierre
  474. * enable signals catching earlier
  475. Revision 1.15 2002/10/30 22:12:13 pierre
  476. * use ppheap with IDEHEAPTRC conditional
  477. Revision 1.14 2002/10/12 19:43:07 hajny
  478. * missing HasSignal conditionals added (needed for FPC/2)
  479. Revision 1.13 2002/09/10 12:19:14 pierre
  480. * use faster method for loading files by default
  481. Revision 1.12 2002/09/09 06:59:16 pierre
  482. * new debug options added
  483. Revision 1.11 2002/09/07 15:40:41 peter
  484. * old logs removed and tabs fixed
  485. Revision 1.10 2002/09/04 14:07:12 pierre
  486. + Enhance code complete by inserting unit symbols
  487. Revision 1.9 2002/05/29 22:29:42 pierre
  488. Asciitab now in fvision
  489. Revision 1.8 2002/04/12 11:28:55 pierre
  490. + use fpcygwin unit for win32 debug IDE
  491. Revision 1.7 2002/04/12 09:00:01 pierre
  492. * enhance internal error handling
  493. Revision 1.6 2002/03/28 16:32:48 pierre
  494. * clearscrenn at exit for unix
  495. Revision 1.5 2002/03/20 14:56:41 pierre
  496. * correct last commit
  497. Revision 1.4 2002/03/20 14:53:37 pierre
  498. + rescue handlers in main loop
  499. Revision 1.3 2002/01/09 09:46:10 pierre
  500. * fix problems with -S option
  501. }